Box::newonly works with dimensions; that is, it takes a size value Tand returns Box<T>. In some places, a Box<T>may be forced to Box<U>(if T: Unsize<U>).
Such coercion does not occur in .map(Box::new), but in Some(Box::new(s)); the latter is basically the same as Some(Box::new(s) as Box<FooTrait>).
You could create (at night) your own box designer that returns fields of non-standard types such as this:
#![feature(unsize)]
fn box_new_unsized<T, U>(v: T) -> Box<U>
where
T: ::std::marker::Unsize<U>,
U: ?Sized,
{
Box::<T>::new(v)
}
and use it like .map(box_new_unsized). See Playground .
source
share