Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TinyBox<T: Sized> usage for no_std compatible error handling as Result<T, dyn Error> #399

Closed
CPerezz opened this issue Feb 12, 2021 · 1 comment
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)

Comments

@CPerezz
Copy link
Contributor

CPerezz commented Feb 12, 2021

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 when size_of_val(&T) > size_of::<usize>() but otherwise stored T internally, and then TinyBox<dyn Trait> could actually work correctly by using size_of_val(&self), which only accesses the vtable, not the actual self data pointer.

We could then make TinyBox work even without alloc, simply by making its non-alloc form panic when size_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 of std::io on top of this trait. This gives you Result<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)

@CPerezz CPerezz added area:API 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) labels Feb 12, 2021
@ZER0 ZER0 removed the area:API label Mar 16, 2021
@autholykos autholykos added team:R&D Research & Development (Cryptographic Protocol) and removed team:Core Low Level Core Development Team (Rust) labels Jul 1, 2021
@ZER0 ZER0 added team:Core Low Level Core Development Team (Rust) and removed team:R&D Research & Development (Cryptographic Protocol) labels Jul 20, 2021
@marta-belles
Copy link
Contributor

Closing it for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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)
Projects
None yet
Development

No branches or pull requests

4 participants