Implement Weak::new_downgraded() (#30425) #30467
Conversation
This adds a constructor for a Weak that can never be upgraded. These are mostly useless, but for example are required when deserializing.
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @brson (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
cc @rust-lang/libs Is everyone cool with this? Does it need an RFC? |
_ptr: Shared::new(Box::into_raw(box RcBox { | ||
strong: Cell::new(0), | ||
weak: Cell::new(1), | ||
value: uninit(), |
apasel422
Dec 18, 2015
Contributor
Can this use core::mem::uninitialized
instead?
Can this use core::mem::uninitialized
instead?
shahn
Dec 18, 2015
Author
Contributor
fixing
fixing
I would probably personally call this |
Should |
@alexcrichton The reason I went with a different name was to make it clear that this won't be usable for "normal" code. Happy to defer to you of course, extending PR. @apasei422 good point! I'll extend the PR. |
I'm thinking if everyone likes this branch I should probably rebase & squash it into a single commit? |
/// | ||
/// use std::sync::Arc; | ||
/// | ||
/// let five = Arc::new(5); |
apasel422
Dec 18, 2015
Contributor
This should be Weak::new
.
This should be Weak::new
.
/// | ||
/// use std::rc::Weak; | ||
/// | ||
/// let empty:Weak<i64> = Weak::new(); |
apasel422
Dec 18, 2015
Contributor
There should be a space before Weak<i64>
.
There should be a space before Weak<i64>
.
issue = "30425")] | ||
pub fn new() -> Weak<T> { | ||
unsafe { | ||
let x: Box<_> = box ArcInner { |
apasel422
Dec 18, 2015
Contributor
Is there a reason this Box
is assigned to a local variable when the one for rc::Weak
isn't?
Is there a reason this Box
is assigned to a local variable when the one for rc::Weak
isn't?
shahn
Dec 19, 2015
Author
Contributor
I mirrored Arc::new(). But I can remove it.
I mirrored Arc::new(). But I can remove it.
This comment has been minimized.
This comment has been minimized.
five? |
This comment has been minimized.
This comment has been minimized.
Not sure how valuable an example that does nothing but call the method is. |
I agree wrt the examples, I added them because they were there for Rc::new and Arc::new (where they also only assign a value). Should I update this? |
I think I addressed all review comments, thanks a bunch. Anything else for me to do except wait while a decision is made? |
@bors r+ |
|
This adds a constructor for a Weak that can never be upgraded. These are mostly useless, but for example are required when deserializing.
This adds a constructor for a Weak that can never be upgraded. These are mostly useless, but for example are required when deserializing.
|
@bors retry |
This adds a constructor for a Weak that can never be upgraded. These are mostly useless, but for example are required when deserializing.
This adds a constructor for a Weak that can never be upgraded. These are
mostly useless, but for example are required when deserializing.