pub struct StaticArc<T: ?Sized> { /* private fields */ }
Expand description

Allows the creation of “reference-counted” globals.

This is achieved by biasing the refcount with +1, which ensures that the count never drops back to zero (unless buggy unsafe code incorrectly decrements without owning an increment) and therefore also ensures that drop is never called.

Examples

use kernel::sync::{Arc, ArcBorrow, StaticArc};

const VALUE: u32 = 10;
static SR: StaticArc<u32> = StaticArc::new(VALUE);

fn takes_ref_borrow(v: ArcBorrow<'_, u32>) {
    assert_eq!(*v, VALUE);
}

fn takes_ref(v: Arc<u32>) {
    assert_eq!(*v, VALUE);
}

takes_ref_borrow(SR.as_arc_borrow());
takes_ref(SR.as_arc_borrow().into());

Implementations

Creates a new instance of a static “ref-counted” object.

Creates a ArcBorrow instance from the given static object.

This requires a 'static lifetime so that it can guarantee that the underlyling object remains valid and is effectively pinned.

Trait Implementations

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
This documentation is an old archive. Please see https://rust.docs.kernel.org instead.