-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Tracking issue for std::ptr::eq, Arc::ptr_eq, and Rc::ptr_eq #36497
Comments
I needed Rc::ptr_eq to avoid a double borrow in a recursive data structure with Rc<RefCell< T >>. Thanks a lot! |
@vadixidav It can be implemented outside of pub fn rc_ptr_eq<T: ?Sized>(this: &Rc<T>, other: &Rc<T>) -> bool {
let this_ptr: *const T = &*this;
let other_ptr: *const T = &*other;
this_ptr == other_ptr
} |
Seem like good/easy APIs to stabilize! @rfcbot fcp merge |
Team member @alexcrichton has proposed to merge this. The next step is review by the rest of the tagged teams: No concerns currently listed. Once these reviewers reach consensus, this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
FWIW, I just found a good use for this in librsvg's port to Rust. Librsvg has a Node structure for the tree of SVG objects. The C code keeps around Sometimes there is code like The things I expose to the C code are pointers that come from This means that
is invalid now. What I want is to
and that can be implemented as
For now I'm using @SimonSapin's code (it's missing double asterisks in |
I sometimes find convenient to make it less generic (when it’s only used with one fn same_node(a: *const Node, b: *const Node) -> bool {
a == b
} This looks the same as #[no_mangle]
pub extern fn rsvg_node_is_same (raw_node1: *const RsvgNode, raw_node2: *const RsvgNode) -> bool {
match (raw_node1.as_ref(), raw_node2.as_ref()) {
(Some(node1), Some(node2)) => same_node(&**node1, &**node2),
(None, None) => true,
_ => false
}
} (Of course, |
ping @BurntSushi (checkbox) |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
The final comment period is now complete. |
For future GitHub travelers, investigating Looks like the methods were stabilized with the |
This is not unique to these |
Implemented in #35992 as
#[unstable(feature = "ptr_eq")]
.std::ptr::eq
is rust-lang/rfcs#1155.The text was updated successfully, but these errors were encountered: