Struct refuse::AnyRef

source ·
pub struct AnyRef { /* private fields */ }
Expand description

A type-erased garbage collected reference.

Implementations§

source§

impl AnyRef

source

pub const fn downcast_ref<T>(&self) -> Ref<T>
where T: Collectable,

Returns a Ref<T>.

This function does not do any type checking. If T is not the correct type, attempting to load the underyling value will fail.

source

pub fn downcast_checked<T>(&self) -> Option<Ref<T>>
where T: Collectable,

Returns a Ref<T>.

This function does not do any type checking. If T is not the correct type, attempting to load the underyling value will fail.

source

pub fn downcast_root<T>(&self, guard: &CollectionGuard<'_>) -> Option<Root<T>>
where T: Collectable,

Returns a Root<T> if the underlying reference points to a T that has not been collected.

source

pub fn load<'guard, T>( &self, guard: &'guard CollectionGuard<'_> ) -> Option<&'guard T>
where T: Collectable,

Loads a reference to the underlying data. Returns None if the data has been collected and is no longer available.

source

pub fn load_mapped<'guard, T>( &self, guard: &'guard CollectionGuard<'_> ) -> Option<&'guard T>
where T: ?Sized + 'static,

Returns a reference to the result of MapAs::map_as(), if the value has not been collected and MapAs::Target is T.

Examples found in repository?
examples/map_as.rs (line 37)
32
33
34
35
36
37
38
39
40
fn main() {
    let guard = CollectionGuard::acquire();
    let gced: Ref<SomeType> = Ref::new(SomeType, &guard);
    let type_erased: AnyRef = gced.as_any();
    type_erased
        .load_mapped::<dyn SomeTrait>(&guard)
        .unwrap()
        .do_something();
}

Trait Implementations§

source§

impl Clone for AnyRef

source§

fn clone(&self) -> AnyRef

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for AnyRef

source§

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

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

impl From<&AnyRef> for AnyRef

source§

fn from(value: &AnyRef) -> Self

Converts to this type from the input type.
source§

impl<T> From<&Ref<T>> for AnyRef
where T: Collectable,

source§

fn from(value: &Ref<T>) -> Self

Converts to this type from the input type.
source§

impl<T> From<&Root<T>> for AnyRef
where T: Collectable,

source§

fn from(value: &Root<T>) -> Self

Converts to this type from the input type.
source§

impl<T> From<Ref<T>> for AnyRef
where T: Collectable,

source§

fn from(value: Ref<T>) -> Self

Converts to this type from the input type.
source§

impl Hash for AnyRef

source§

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

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 Ord for AnyRef

source§

fn cmp(&self, other: &AnyRef) -> 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 + PartialOrd,

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

impl<T> PartialEq<&AnyRef> for Ref<T>
where T: Collectable,

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T> PartialEq<&AnyRef> for Root<T>
where T: Collectable,

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T> PartialEq<AnyRef> for Ref<T>
where T: Collectable,

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T> PartialEq<AnyRef> for Root<T>
where T: Collectable,

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq for AnyRef

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd for AnyRef

source§

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

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

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

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

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

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

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

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Trace for AnyRef

source§

const MAY_CONTAIN_REFERENCES: bool = true

If true, this type may contain references and should have its trace() function invoked during the collector’s “mark” phase.
source§

fn trace(&self, tracer: &mut Tracer<'_>)

Traces all refrences that this value references. Read more
source§

impl Copy for AnyRef

source§

impl Eq for AnyRef

source§

impl StructuralPartialEq for AnyRef

Auto Trait Implementations§

§

impl Freeze for AnyRef

§

impl RefUnwindSafe for AnyRef

§

impl Send for AnyRef

§

impl Sync for AnyRef

§

impl Unpin for AnyRef

§

impl UnwindSafe for AnyRef

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<A> Cast for A

source§

fn cast<To>(self) -> To
where To: CastFrom<A>,

Casts self to the To type. This may be a lossy operation.
source§

impl<A> CastFrom<A> for A

source§

fn from_cast(from: A) -> A

Returns from as Self.
source§

impl<A, B> CastInto<A> for B
where A: CastFrom<B>,

source§

fn cast_into(self) -> A

Returns self as To.
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<Key, SearchFor> Sort<SearchFor> for Key
where Key: Ord + PartialOrd<SearchFor>,

source§

fn compare(&self, b: &SearchFor) -> Ordering

Compare self and other, returning the comparison result. Read more
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

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

§

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.