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

Add unsize_box! macro to allow safe creation of Box<T: !Sized> on stable #6

Merged
merged 1 commit into from
Apr 18, 2024

Conversation

fu5ha
Copy link
Contributor

@fu5ha fu5ha commented Sep 4, 2023

Under stable feature, adds unsize_box! macro which takes as input a Box to a T: Sized and coerces it to a U: !Sized which can be safely unsize-coerced from T.

use allocator_api2::unsize_box;
use allocator_api2::boxed::Box;
use core::any::Any;

let sized_box: Box<u64> = Box::new(0);
let unsized_box: Box<dyn Any> = unsize_box!(sized_box);

See this discussion on the rust community discord for discussion, added a comment that explains it in the code as well https://discord.com/channels/273534239310479360/592856094527848449/1148216815844081734

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants