I have a trait object, and I want to know the concrete object that it points to, but I cannot work out how to get the concrete object.
What I want is something like the following:
trait MyClonable {
/** copy from another MyClonable */
fn my_clone_from(&mut self, other: &Self)->Result<(), MyError>;
}
impl MyClonable for SomeType {
fn my_clone_from(&mut self, other: &MyClonable)->Result<(), MyError> {...}
}
So that I can say something like:
let mut new_thing = SomeType::new();
new_thing.my_clone_from(&old_thing)?;
Then the new_thing
will contain a sort-of copy of the old_thing
, unless old_thing
is of an unexpected type, in which case it should return an error.
But Rust will not let me get something like an Option<&SomeType>
from a MyClonable
.