Skip to main content

RefCounted

Struct RefCounted 

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

An explicitly counted reference to a shared resource.

Every reference is disposed on its own; the resource is released when the last one is disposed. A reference that is dropped without having been disposed releases its count as well.

References are shared between the UI thread and the render thread: the count is atomic, as in the original.

Implementations§

Source§

impl<T: ?Sized + 'static> RefCounted<T>

Source

pub fn dispose(&self)

Releases this reference.

Source

pub fn item(&self) -> Arc<T> ⓘ

The referenced resource. Panics if this reference has been disposed.

Source

pub fn clone_ref(&self) -> RefCounted<T>

Creates another reference to the resource. Panics if this reference has been disposed.

Source

pub fn clone_as<TResult: ?Sized + 'static>( &self, cast: impl FnOnce(Arc<T>) -> Arc<TResult>, ) -> RefCounted<TResult>

Creates another reference to the resource, viewed as another type. Panics if this reference has been disposed.

Source

pub fn is_alive(&self) -> bool

Whether this reference has not been disposed.

Source

pub fn ref_count(&self) -> i32

The number of live references to the resource. Panics if this reference has been disposed.

Trait Implementations§

Source§

impl<T: ?Sized + 'static> Drop for RefCounted<T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl<T> !Freeze for RefCounted<T>

§

impl<T> RefUnwindSafe for RefCounted<T>
where Mutex<Option<Arc<T>>>: RefUnwindSafe, T: ?Sized,

§

impl<T> Send for RefCounted<T>
where Mutex<Option<Arc<T>>>: Send, T: ?Sized,

§

impl<T> Sync for RefCounted<T>
where Mutex<Option<Arc<T>>>: Sync, T: ?Sized,

§

impl<T> Unpin for RefCounted<T>
where Mutex<Option<Arc<T>>>: Unpin, T: ?Sized,

§

impl<T> UnsafeUnpin for RefCounted<T>
where Mutex<Option<Arc<T>>>: UnsafeUnpin, T: ?Sized,

§

impl<T> UnwindSafe for RefCounted<T>
where Mutex<Option<Arc<T>>>: UnwindSafe, 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> ClassDefaults for T
where T: ?Sized,

Source§

fn static_constructor()

The static constructor of a type: work done once per thread, after the properties of the type are registered and before its first instance exists (class handlers, affects_render, metadata overrides). 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.