left_right::aliasing

Struct Aliased

Source
pub struct Aliased<T, D>
where D: DropBehavior,
{ /* private fields */ }
Expand description

A T that is aliased.

You should be able to mostly ignore this type, as it can generally be treated exactly like a &T. However, there are some minor exceptions around forwarding traits – since Aliased is a wrapper type around T, it cannot automatically forward traits it does not know about to &T. This means that if your &T implements, say, Serialize or some custom Borrow<Q>, Aliased<T> will not implement that same trait. You can work around this either by implementing your trait specifically for Aliased<T> where possible, or by manually dereferencing to get the &T before using the trait.

Implementations§

Source§

impl<T, D> Aliased<T, D>
where D: DropBehavior,

Source

pub unsafe fn alias(&self) -> Self

Create an alias of the inner T.

§Safety

This method is only safe to call as long as you ensure that the alias is never used after an Aliased<T, D> of self where D::DO_DROP is true is dropped, and as long as no &mut T is ever given out while some Aliased<T> may still be used. The returned type assumes that it is always safe to dereference into &T, which would not be true if either of those invariants were broken.

Source

pub fn from(t: T) -> Self

Construct an aliased value around a T.

This method is safe since it effectively leaks T. Note that we do not implement From<T> because we do not want users to construct Aliased<T>s on their own. If they did, they would almost certain end up with incorrect drop behavior.

Source

pub unsafe fn change_drop<D2: DropBehavior>(self) -> Aliased<T, D2>

Turn this aliased T into one with a different drop behavior.

§Safety

It is always safe to change an Aliased from a dropping D to a non-dropping D. Going the other way around is only safe if self is the last alias for the T.

Trait Implementations§

Source§

impl<T, D> AsRef<T> for Aliased<T, D>
where D: DropBehavior,

Source§

fn as_ref(&self) -> &T

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<T, D> Borrow<[T]> for Aliased<Vec<T>, D>
where D: DropBehavior,

Source§

fn borrow(&self) -> &[T]

Immutably borrows from an owned value. Read more
Source§

impl<D> Borrow<Path> for Aliased<PathBuf, D>
where D: DropBehavior,

Source§

fn borrow(&self) -> &Path

Immutably borrows from an owned value. Read more
Source§

impl<T, D> Borrow<T> for Aliased<Arc<T>, D>
where T: ?Sized, D: DropBehavior,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T, D> Borrow<T> for Aliased<Box<T>, D>
where T: ?Sized, D: DropBehavior,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T, D> Borrow<T> for Aliased<Rc<T>, D>
where T: ?Sized, D: DropBehavior,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T, D> Borrow<T> for Aliased<T, D>
where D: DropBehavior,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<D> Borrow<str> for Aliased<String, D>
where D: DropBehavior,

Source§

fn borrow(&self) -> &str

Immutably borrows from an owned value. Read more
Source§

impl<T, D> Debug for Aliased<T, D>
where D: DropBehavior, T: Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T, D> Deref for Aliased<T, D>
where D: DropBehavior,

Source§

type Target = T

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<T, D> Drop for Aliased<T, D>
where D: DropBehavior,

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<T, D> Hash for Aliased<T, D>
where D: DropBehavior, T: Hash,

Source§

fn hash<H>(&self, state: &mut H)
where H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<T, D> Ord for Aliased<T, D>
where D: DropBehavior, T: Ord,

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<T, D> PartialEq for Aliased<T, D>
where D: DropBehavior, T: PartialEq,

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T, D> PartialOrd for Aliased<T, D>
where D: DropBehavior, T: PartialOrd,

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<T, D> Eq for Aliased<T, D>
where D: DropBehavior, T: Eq,

Source§

impl<T, D> Send for Aliased<T, D>
where D: DropBehavior, T: Send + Sync,

Source§

impl<T, D> Sync for Aliased<T, D>
where D: DropBehavior, T: Sync,

Auto Trait Implementations§

§

impl<T, D> Freeze for Aliased<T, D>
where T: Freeze,

§

impl<T, D> RefUnwindSafe for Aliased<T, D>

§

impl<T, D> Unpin for Aliased<T, D>
where D: Unpin, T: Unpin,

§

impl<T, D> UnwindSafe for Aliased<T, D>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.