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); } 
  1. i want check if foo_instance references same instance *some_vector[0], can't ...

  2. 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

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -