Any way to support dyn types in custom Box?
โ Rust ๐ 2026-03-22 ๐ค surdeus ๐๏ธ 3In my implementation of Box, to allow boxing of dyn values, I want to add
use std::ops::CoerceUnsized;
use std::marker::Unsize;
impl<T: ?Sized + Unsize<U>, U: ?Sized, A: Allocator> CoerceUnsized<Box<U, A>> for Box<T, A> {}
but this is not possible under stable, it requires the features unsize and coerce_unsized.
I donโt think there is any way around this, is that correct?
It seems a shame that in 2026 dyn types are not yet fully supported on stable. I am thinking about a dirty work-around, such as temporarily switching the Global allocator to bump allocate for the current thread, but it seems rather nasty.
Or maybe just switch to using nightly until this is stabilised, I guess.
Well, I decided to have a feature that requires nightly, that seems a reasonable way to proceed.
6 posts - 2 participants
๐ท๏ธ Rust_feed