pub enum Shared<'gc, T: 'gc + Collect> {
Unique(T),
Aliased(Gc<'gc, RefLock<T>>),
}
Expand description
Represents a shared mutable resource.
This is effectively equivalent to Gc<T>
except that it performs no dynamic allocation
for the Shared::Unique
case, which is assumed to be significantly more likely than Shared::Aliased
.
Variants§
Unique(T)
A shared resource which has only (this) single unique handle.
Aliased(Gc<'gc, RefLock<T>>)
One of several handles to a single shared resource.
Implementations§
Sourcepub fn get(&self) -> SharedRef<'_, T>
pub fn get(&self) -> SharedRef<'_, T>
Gets a reference to the shared resource’s currently stored value.
Sourcepub fn alias_inner(&mut self, mc: &Mutation<'gc>) -> Gc<'gc, RefLock<T>>
pub fn alias_inner(&mut self, mc: &Mutation<'gc>) -> Gc<'gc, RefLock<T>>
Transitions the shared value from Shared::Unique
to Shared::Aliased
if it has not already,
and returns an additional alias to the underlying value.
Sourcepub fn alias(&mut self, mc: &Mutation<'gc>) -> Self
pub fn alias(&mut self, mc: &Mutation<'gc>) -> Self
Creates a new instance of Shared
that references the same underlying value.
This is equivalent to constructing an instance of Shared::Aliased
with the result of Shared::alias_inner
.
Trait Implementations§
Source§fn needs_trace() -> bool
fn needs_trace() -> bool
As an optimization, if this type can never hold a
Gc
pointer and trace
is unnecessary
to call, you may implement this method and return false. The default implementation returns
true, signaling that Collect::trace
must be called.Source§fn trace(&self, cc: &Collection)
fn trace(&self, cc: &Collection)
Must call
Collect::trace
on all held Gc
pointers. If this type holds inner types that
implement Collect
, a valid implementation would simply call Collect::trace
on all the
held values to ensure this.Auto Trait Implementations§
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more