Struct left_right::aliasing::Aliased
source · [−]#[repr(transparent)]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
sourceimpl<T, D> Aliased<T, D> where
D: DropBehavior,
impl<T, D> Aliased<T, D> where
D: DropBehavior,
sourcepub unsafe fn alias(&self) -> Self
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.
sourcepub fn from(t: T) -> Self
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.
sourcepub unsafe fn change_drop<D2: DropBehavior>(self) -> Aliased<T, D2>
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
sourceimpl<T, D> AsRef<T> for Aliased<T, D> where
D: DropBehavior,
impl<T, D> AsRef<T> for Aliased<T, D> where
D: DropBehavior,
sourceimpl<T, D> Borrow<T> for Aliased<T, D> where
D: DropBehavior,
impl<T, D> Borrow<T> for Aliased<T, D> where
D: DropBehavior,
sourceimpl<T, D> Debug for Aliased<T, D> where
D: DropBehavior,
T: Debug,
impl<T, D> Debug for Aliased<T, D> where
D: DropBehavior,
T: Debug,
sourceimpl<T, D> Deref for Aliased<T, D> where
D: DropBehavior,
impl<T, D> Deref for Aliased<T, D> where
D: DropBehavior,
sourceimpl<T, D> Drop for Aliased<T, D> where
D: DropBehavior,
impl<T, D> Drop for Aliased<T, D> where
D: DropBehavior,
sourceimpl<T, D> Hash for Aliased<T, D> where
D: DropBehavior,
T: Hash,
impl<T, D> Hash for Aliased<T, D> where
D: DropBehavior,
T: Hash,
sourceimpl<T, D> Ord for Aliased<T, D> where
D: DropBehavior,
T: Ord,
impl<T, D> Ord for Aliased<T, D> where
D: DropBehavior,
T: Ord,
sourceimpl<T, D> PartialOrd<Aliased<T, D>> for Aliased<T, D> where
D: DropBehavior,
T: PartialOrd,
impl<T, D> PartialOrd<Aliased<T, D>> for Aliased<T, D> where
D: DropBehavior,
T: PartialOrd,
sourcefn partial_cmp(&self, other: &Self) -> Option<Ordering>
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
sourcefn lt(&self, other: &Self) -> bool
fn lt(&self, other: &Self) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
sourcefn le(&self, other: &Self) -> bool
fn le(&self, other: &Self) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
impl<T, D> Eq for Aliased<T, D> where
D: DropBehavior,
T: Eq,
impl<T, D> Send for Aliased<T, D> where
D: DropBehavior,
T: Send + Sync,
impl<T, D> Sync for Aliased<T, D> where
D: DropBehavior,
T: Sync,
Auto Trait Implementations
impl<T, D> RefUnwindSafe for Aliased<T, D> where
D: RefUnwindSafe,
T: RefUnwindSafe,
impl<T, D> Unpin for Aliased<T, D> where
D: Unpin,
T: Unpin,
impl<T, D> UnwindSafe for Aliased<T, D> where
D: UnwindSafe,
T: UnwindSafe + RefUnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more