-
Notifications
You must be signed in to change notification settings - Fork 13.8k
implement Box::take
#147227
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
implement Box::take
#147227
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current wording is great! I'd maybe add a note (and a line in the example) about using Box::write
to reinitialise the Box
, as these functions are meant to be used together.
let (raw, alloc) = Box::into_raw_with_allocator(boxed); | ||
let value = raw.read(); | ||
let uninit = Box::from_raw_in(raw.cast::<mem::MaybeUninit<T>>(), alloc); | ||
(value, uninit) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you use Box::into_non_null_with_allocator
and NonNull::cast_uninit
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure! However since this has already been r+'ed, I think I'll save that change for the inevitable renaming of the function, since as far as I can tell the semantics are identical from the outside.
Thanks! |
implement `Box::take` Tracking issue: rust-lang#147212 I'm not entirely sure about the wording of the doc comment, if anyone has any suggestions that'd be great :)
Rollup of 10 pull requests Successful merges: - #146281 (Support `#[rustc_align_static]` inside `thread_local!`) - #146535 (mbe: Implement `unsafe` attribute rules) - #146585 (indexing: reword help) - #147004 (Tweak handling of "struct like start" where a struct isn't supported) - #147221 (Forbid `//@ compile-flags: -Cincremental=` in tests) - #147225 (Don't enable shared memory by default with Wasm atomics) - #147227 (implement `Box::take`) - #147231 (Extending `#[rustc_force_inline]` to be applicable to inherent methods) - #147233 (Initialize llvm submodule if not already the case to run citool) - #147236 (Update books) r? `@ghost` `@rustbot` modify labels: rollup
implement `Box::take` Tracking issue: rust-lang#147212 I'm not entirely sure about the wording of the doc comment, if anyone has any suggestions that'd be great :)
implement `Box::take` Tracking issue: rust-lang#147212 I'm not entirely sure about the wording of the doc comment, if anyone has any suggestions that'd be great :)
Rollup of 9 pull requests Successful merges: - #146281 (Support `#[rustc_align_static]` inside `thread_local!`) - #146535 (mbe: Implement `unsafe` attribute rules) - #146585 (indexing: reword help) - #147004 (Tweak handling of "struct like start" where a struct isn't supported) - #147221 (Forbid `//@ compile-flags: -Cincremental=` in tests) - #147225 (Don't enable shared memory by default with Wasm atomics) - #147227 (implement `Box::take`) - #147233 (Initialize llvm submodule if not already the case to run citool) - #147236 (Update books) r? `@ghost` `@rustbot` modify labels: rollup
Rollup of 9 pull requests Successful merges: - rust-lang/rust#146281 (Support `#[rustc_align_static]` inside `thread_local!`) - rust-lang/rust#146535 (mbe: Implement `unsafe` attribute rules) - rust-lang/rust#146585 (indexing: reword help) - rust-lang/rust#147004 (Tweak handling of "struct like start" where a struct isn't supported) - rust-lang/rust#147221 (Forbid `//@ compile-flags: -Cincremental=` in tests) - rust-lang/rust#147225 (Don't enable shared memory by default with Wasm atomics) - rust-lang/rust#147227 (implement `Box::take`) - rust-lang/rust#147233 (Initialize llvm submodule if not already the case to run citool) - rust-lang/rust#147236 (Update books) r? `@ghost` `@rustbot` modify labels: rollup
Tracking issue: #147212
I'm not entirely sure about the wording of the doc comment, if anyone has any suggestions that'd be great :)