Trait Same

Source
pub trait Same {
    // Required method
    fn same(&self, other: &Self) -> bool;
}
Expand description

Allows to test identity of objects.

§Example:

use same::Same;

let a = 42;
let b = 42;
let a_ref0 = &a;
let a_ref1 = &a;
let b_ref = &b;

// `a_ref0` and `a_ref1` point to the same object...
assert!(a_ref0.same(&a_ref1));
// ... but `a_ref0` and `b_ref` don't...
assert!(!a_ref0.same(&b_ref));
// ... neither do `a_ref1` and `b_ref`.
assert!(!a_ref1.same(&b_ref));

This trait is currently implemented for shared references, Rc and Arc.

Note that it doesn’t make sense to implement this trait for mutable references, nor boxes because there can never be two of them pointing to the same address, so the implementation would always return false.

Required Methods§

Source

fn same(&self, other: &Self) -> bool

Returns true if self is the same instance of object as other.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<'a, T> Same for &'a T

Source§

fn same(&self, other: &Self) -> bool

Source§

impl<T> Same for Rc<T>

Source§

fn same(&self, other: &Self) -> bool

Source§

impl<T> Same for Arc<T>

Source§

fn same(&self, other: &Self) -> bool

Implementors§