pub struct ArcBorrow<'a, T: ?Sized + 'a> { /* private fields */ }
Expand description

A borrowed reference to an Arc instance.

For cases when one doesn’t ever need to increment the refcount on the allocation, it is simpler to use just &T, which we can trivially get from an Arc<T> instance.

However, when one may need to increment the refcount, it is preferable to use an ArcBorrow<T> over &Arc<T> because the latter results in a double-indirection: a pointer (shared reference) to a pointer (Arc<T>) to the object (T). An ArcBorrow eliminates this double indirection while still allowing one to increment the refcount and getting an Arc<T> when/if needed.


There are no mutable references to the underlying Arc, and it remains valid for the lifetime of the ArcBorrow instance.


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

struct Example;

fn do_something(e: ArcBorrow<'_, Example>) -> Arc<Example> {

let obj = Arc::try_new(Example)?;
let cloned = do_something(obj.as_arc_borrow());

// Assert that both `obj` and `cloned` point to the same underlying object.
assert!(core::ptr::eq(&*obj, &*cloned));

Using ArcBorrow<T> as the type of self:

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

struct Example {
    a: u32,
    b: u32,

impl Example {
    fn use_reference(self: ArcBorrow<'_, Self>) {
        // ...

let obj = Arc::try_new(Example { a: 10, b: 20 })?;

Trait Implementations

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
The resulting type after dereferencing.
Dereferences the value.
Converts to this type from the input type.

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 resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
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.