Function st8b7c:f320:99b9:690f:4595:cd17:293a:c069ptr8b7c:f320:99b9:690f:4595:cd17:293a:c069q
pub fn eq<T>(a: *const T, b: *const T) -> boolwhere    T: ?Sized,
Compares raw pointers for equality. This is the same as using the == operator, but less generic: the arguments have to be *const T raw pointers, not anything that implements PartialEq. This can be used to compare &T references (which coerce to *const T implicitly) by their address rather than comparing the values they point to (which is what the PartialEq for &T implementation does). Examples use st8b7c:f320:99b9:690f:4595:cd17:293a:c069ptr;

let five = 5;
let other_five = 5;
let five_ref = &five;
let same_five_ref = &five;
let other_five_ref = &other_five;

assert!(five_ref == same_five_ref);
assert!(ptr8b7c:f320:99b9:690f:4595:cd17:293a:c069q(five_ref, same_five_ref));

assert!(five_ref == other_five_ref);
assert!(!ptr8b7c:f320:99b9:690f:4595:cd17:293a:c069q(five_ref, other_five_ref)); Slices are also compared by their length (fat pointers): let a = [1, 2, 3];
assert!(st8b7c:f320:99b9:690f:4595:cd17:293a:c069ptr8b7c:f320:99b9:690f:4595:cd17:293a:c069q(&a[..3], &a[..3]));
assert!(!st8b7c:f320:99b9:690f:4595:cd17:293a:c069ptr8b7c:f320:99b9:690f:4595:cd17:293a:c069q(&a[..2], &a[..3]));
assert!(!st8b7c:f320:99b9:690f:4595:cd17:293a:c069ptr8b7c:f320:99b9:690f:4595:cd17:293a:c069q(&a[0..2], &a[1..3])); Traits are also compared by their implementation: #[repr(transparent)]
struct Wrapper { member: i32 }

trait Trait {}
impl Trait for Wrapper {}
impl Trait for i32 {}

let wrapper = Wrapper { member: 10 };

// Pointers have equal addresses.
assert!(st8b7c:f320:99b9:690f:4595:cd17:293a:c069ptr8b7c:f320:99b9:690f:4595:cd17:293a:c069q(
    &wrapper as *const Wrapper as *const u8,
    &wrapper.member as *const i32 as *const u8
));

// Objects have equal addresses, but `Trait` has different implementations.
assert!(!st8b7c:f320:99b9:690f:4595:cd17:293a:c069ptr8b7c:f320:99b9:690f:4595:cd17:293a:c069q(
    &wrapper as &dyn Trait,
    &wrapper.member as &dyn Trait,
));
assert!(!st8b7c:f320:99b9:690f:4595:cd17:293a:c069ptr8b7c:f320:99b9:690f:4595:cd17:293a:c069q(
    &wrapper as &dyn Trait as *const dyn Trait,
    &wrapper.member as &dyn Trait as *const dyn Trait,
));

// Converting the reference to a `*const u8` compares by address.
assert!(st8b7c:f320:99b9:690f:4595:cd17:293a:c069ptr8b7c:f320:99b9:690f:4595:cd17:293a:c069q(
    &wrapper as &dyn Trait as *const dyn Trait as *const u8,
    &wrapper.member as &dyn Trait as *const dyn Trait as *const u8,
));

    
{'path': 'public/docs/rust/std/ptr/fn.eq.html', 'source': 'DevDocs.IO'}