If I know that I put in a
Box<T>, but stored the Box as
Box<Any + Send + Sync> (heterogeneous collection), is it "safe"-ish to transmute that back into a
I have a
Vec<Box<Trait>>, where Trait includes a method that returns
Box<Any + Send + Sync> and a method that accepts the same
Box<Any + Send + Sync> returned by the previous method. (Parallel
Vec<Box<Any>> of the same size keeps track of these).
In the impl of
Trait, is it safe for me to return
Box<T> and then later transmute the incoming
Box<Any + Send + Sync> to
Box<T>? I feel like this is probably valid, and the unsafe block is required because it's impossible to guarantee at compile time that the incoming
Box<Any + Send + Sync> is the same as the one returned by a different function. But if I can make that guarantee at runtime, then the unsafe transmute should be fine. Am I missing something?
Alternatively, of course, is there a better way to do what I'm doing? (Store data from Trait objects that is later returned to the same Trait objects?)