TinyBox<T: Sized> usage for no_std compatible error handling as Result<T, dyn Error> #399
Labels
need:help
Call for participation: Help is requested to fix this issue
status:minor
Low priority improvements
team:Core
Low Level Core Development Team (Rust)
All true rust types know their size and alignment, which
dyn Trait
types accomplish using their vtable.In consequence, one could build a
TinyBox<T: Sized>
type that allocated whensize_of_val(&T) > size_of::<usize>()
but otherwise storedT
internally, and thenTinyBox<dyn Trait>
could actually work correctly by usingsize_of_val(&self)
, which only accesses the vtable, not the actualself
data pointer.We could then make
TinyBox
work even without alloc, simply by making its non-alloc form panic whensize_of_val(&T) > size_of::<usize>()
.At this point, if one has a no_std compatable
Error
trait then one could rebuild the entire trait infrastructure ofstd::io
on top of this trait. This gives youResult<T,dyn Error>
which works even without alloc for small enums, OS ernos, etc., but not large complex error types with backtrace allocations, etc.I've zero time to implement this, but if anyone gets interested then I'm happy to give some pointers.
cc rust-lang/project-error-handling#20
Originally posted by @burdges in #343 (comment)
The text was updated successfully, but these errors were encountered: