rust_cc

Struct Cc

Source
pub struct Cc<T: ?Sized + Trace + 'static> { /* private fields */ }
Expand description

A thread-local cycle collected pointer.

See the module-level documentation for more details.

Implementations§

Source§

impl<T: Trace> Cc<T>

Source

pub fn new(t: T) -> Cc<T>

Creates a new Cc.

§Collection

This method may start a collection when the auto-collect feature is enabled.

See the config module documentation for more details.

§Panics

Panics if the automatically-stared collection panics.

Source

pub fn try_unwrap(self) -> Result<T, Self>

Returns the inner value, if the Cc has exactly one strong reference and the collector is not collecting, finalizing or dropping.

Otherwise, an Err is returned with the same Cc this method was called on.

This will succeed even if there are outstanding weak references.

Source§

impl<T: ?Sized + Trace> Cc<T>

Source

pub fn ptr_eq(this: &Cc<T>, other: &Cc<T>) -> bool

Returns true if the two Ccs point to the same allocation. This function ignores the metadata of dyn Trait pointers.

Source

pub fn strong_count(&self) -> u32

Returns the number of Ccs to the pointed allocation.

Source

pub fn finalize_again(&mut self)

Available on crate feature finalization only.

Makes the value in the managed allocation finalizable again.

§Panics

Panics if called during a collection.

Source

pub fn already_finalized(&self) -> bool

Available on crate feature finalization only.

Returns true if the value in the managed allocation has already been finalized, false otherwise.

Source

pub fn mark_alive(&self)

Marks the managed allocation as alive.

Every time a Cc is dropped, the pointed allocation is buffered to be processed in the next collection. This method simply removes the managed allocation from the buffer, potentially reducing the amount of work needed to be done by the collector.

This method is a no-op when called on a Cc pointing to an allocation which is not buffered.

Source§

impl<T: Trace> Cc<T>

Source

pub fn new_cyclic<F>(f: F) -> Cc<T>
where F: FnOnce(&Weak<T>) -> T,

Available on crate feature weak-ptrs only.

Creates a new Cc<T> while providing a Weak<T> pointer to the allocation, to allow the creation of a T which holds a weak pointer to itself.

§Collection

This method may start a collection when the auto-collect feature is enabled.

See the config module documentation for more details.

§Panics

Panics if the provided closure or the automatically-stared collection panics.

§Example
#[derive(Trace, Finalize)]
struct Cyclic {
    cyclic: Weak<Self>,
}

let cyclic = Cc::new_cyclic(|weak| {
    Cyclic {
         cyclic: weak.clone(),
    }
});
Source§

impl<T: ?Sized + Trace> Cc<T>

Source

pub fn downgrade(&self) -> Weak<T>

Available on crate feature weak-ptrs only.

Creates a new Weak pointer to the managed allocation, increasing the weak reference count.

§Panics

Panics if the strong reference count exceeds the maximum supported.

Source

pub fn weak_count(&self) -> u32

Available on crate feature weak-ptrs only.

Returns the number of Weaks to the pointed allocation.

Trait Implementations§

Source§

impl<T: ?Sized + Trace> AsRef<T> for Cc<T>

Source§

fn as_ref(&self) -> &T

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

impl<T: ?Sized + Trace> Borrow<T> for Cc<T>

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T: ?Sized + Trace> Clone for Cc<T>

Source§

fn clone(&self) -> Self

Makes a clone of the Cc pointer.

This creates another pointer to the same allocation, increasing the strong reference count.

Cloning a Cc also marks the managed allocation as alive. See mark_alive for more details.

§Panics

Panics if the strong reference count exceeds the maximum supported.

1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<T: ?Sized + Trace + Debug> Debug for Cc<T>

Source§

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

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

impl<T: Trace + Default> Default for Cc<T>

Source§

fn default() -> Self

Creates a new Cc<T>, with the Default value for T.

§Collection

This method may start a collection when the auto-collect feature is enabled.

See the config module documentation for more details.

Source§

impl<T: ?Sized + Trace> Deref for Cc<T>

Source§

type Target = T

The resulting type after dereferencing.
Source§

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

Dereferences the value.
Source§

impl<T: ?Sized + Trace + Display> Display for Cc<T>

Source§

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

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

impl<T: ?Sized + Trace> Drop for Cc<T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<T: ?Sized + Trace> Finalize for Cc<T>

Source§

fn finalize(&self)

The finalizer, which is called after an object becomes garbage and before droping it. Read more
Source§

impl<T: Trace> From<T> for Cc<T>

Source§

fn from(value: T) -> Self

Converts a generic T into a Cc<T>.

§Collection

This method may start a collection when the auto-collect feature is enabled.

See the config module documentation for more details.

Source§

impl<T: ?Sized + Trace + Hash> Hash for Cc<T>

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<T: ?Sized + Trace + Ord> Ord for Cc<T>

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: ?Sized + Trace + PartialEq> PartialEq for Cc<T>

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: ?Sized + Trace + PartialOrd> PartialOrd for Cc<T>

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: ?Sized + Trace> Pointer for Cc<T>

Source§

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

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

impl<T: ?Sized + Trace> Trace for Cc<T>

Source§

fn trace(&self, ctx: &mut Context<'_>)

Traces the contained Ccs. See Trace for more information.
Source§

impl<T: ?Sized + Trace + 'static + Unsize<__S>, __S: ?Sized + Trace + 'static> CoerceUnsized<Cc<__S>> for Cc<T>

Source§

impl<T: ?Sized + Trace + 'static + Unsize<__S>, __S: ?Sized + Trace + 'static> DispatchFromDyn<Cc<__S>> for Cc<T>

Source§

impl<T: ?Sized + Trace + Eq> Eq for Cc<T>

Source§

impl<T: ?Sized + Trace + RefUnwindSafe> RefUnwindSafe for Cc<T>

Source§

impl<T: ?Sized + Trace + UnwindSafe> UnwindSafe for Cc<T>

Auto Trait Implementations§

§

impl<T> Freeze for Cc<T>
where T: ?Sized,

§

impl<T> !Send for Cc<T>

§

impl<T> !Sync for Cc<T>

§

impl<T> Unpin for Cc<T>
where T: ?Sized,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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<T> ToOwned for T
where T: Clone,

Source§

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> ToString for T
where T: Display + ?Sized,

Source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
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.