# RefCounted

Version: 0.5.0
Framework commit: d503df2befa756e681fcdc6250e9552dc7388bea
Canonical URL: /docs/0.5.0/api/ferroui-base/utilities/struct-refcounted/

**struct** · [`ferroui-base`](/docs/0.5.0/api/ferroui-base/) · v0.5.0

```rust
struct RefCounted<T: ?Sized + 'static>
```

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.

[View source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/ref_countable.rs#L61)

## Members

- [`dispose`](#function-dispose)
- [`item`](#function-item)
- [`clone_ref`](#function-clone_ref)
- [`clone_as`](#function-clone_as)
- [`is_alive`](#function-is_alive)
- [`ref_count`](#function-ref_count)

<a id="function-dispose"></a>

### dispose

```rust
fn dispose(self: &Self)
```

Releases this reference.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/ref_countable.rs#L68)

<a id="function-item"></a>

### item

```rust
fn item(self: &Self) -> Arc<T>
```

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

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/ref_countable.rs#L76)

<a id="function-clone_ref"></a>

### clone_ref

```rust
fn clone_ref(self: &Self) -> RefCounted<T>
```

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

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/ref_countable.rs#L84)

<a id="function-clone_as"></a>

### clone_as

```rust
fn clone_as<TResult: ?Sized + 'static>(self: &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](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/ref_countable.rs#L90)

<a id="function-is_alive"></a>

### is_alive

```rust
fn is_alive(self: &Self) -> bool
```

Whether this reference has not been disposed.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/ref_countable.rs#L106)

<a id="function-ref_count"></a>

### ref_count

```rust
fn ref_count(self: &Self) -> i32
```

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

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/ref_countable.rs#L112)

## Trait implementations

- `Send`
- `Sync`
- `Freeze`
- `UnsafeUnpin`
- `Unpin`
- `UnwindSafe`
- `RefUnwindSafe`
- [`ClassDefaults`](/docs/0.5.0/api/ferroui-base/trait-classdefaults/)
- `Borrow<T>`
- `BorrowMut<T>`
- `Into<U>`
- `From<T>`
- `TryInto<U>`
- `TryFrom<U>`
- `Any`
- `ErasedDestructor`
- `IntoEither`
- `Drop`

## Availability

Extracted for `aarch64-apple-darwin`. Cargo features are listed in the [crate index](/docs/0.5.0/api/).
