pointers - How to check if two variables point to the same object in memory? -
for example:
struct foo<'a> { bar: &'a str } fn main() { let foo_instance = foo { bar: "bar" }; let some_vector: vec<&foo> = vec![&foo_instance]; assert!(*some_vector[0] == foo_instance); }
i want check if
foo_instance
references same instance*some_vector[0]
, can't ...i don't want know if 2 instances equal; want check if variables point same instance in memory
is possible that?
i did digging on rust's github , found out there used function in std
, it's not there anymore. there open rfc have back.
for can perform cast *const t
:
assert!(some_vector[0] *const foo == &foo_instance *const foo);
it should check if references point same place in memory.
Comments
Post a Comment