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