# ReadOnlyMemory

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

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

```rust
struct ReadOnlyMemory<T>
```

An immutable, reference counted slice of a shared buffer.

Cloning and slicing never copy the elements; they bump one reference count.

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

## Members

- [`empty`](#function-empty)
- [`new`](#function-new)
- [`with_range`](#function-with_range)
- [`from_vec`](#function-from_vec)
- [`len`](#function-len)
- [`is_empty`](#function-is_empty)
- [`span`](#function-span)
- [`slice_from`](#function-slice_from)
- [`slice`](#function-slice)
- [`offset_in_owner`](#function-offset_in_owner)
- [`owner`](#function-owner)
- [`shares_owner_with`](#function-shares_owner_with)
- [`from_slice`](#function-from_slice)
- [`to_vec`](#function-to_vec)
- [`from_str`](#function-from_str)
- [`to_string_lossy`](#function-to_string_lossy)

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

### empty

```rust
const fn empty() -> Self
```

The empty memory (C# `default` / `ReadOnlyMemory<T>.Empty`).

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

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

### new

```rust
fn new(owner: Rc<[T]>) -> Self
```

Wraps a whole shared buffer.

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

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

### with_range

```rust
fn with_range(owner: Rc<[T]>, start: usize, length: usize) -> Self
```

Wraps `length` elements of a shared buffer starting at `start`.

Panics when the range is outside the buffer.

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

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

### from_vec

```rust
fn from_vec(values: Vec<T>) -> Self
```

Takes ownership of a vector.

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

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

### len

```rust
fn len(self: &Self) -> usize
```

The number of elements (C# `Length`).

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

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

### is_empty

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

Whether the memory has no elements (C# `IsEmpty`).

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

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

### span

```rust
fn span(self: &Self) -> &[T]
```

The elements (C# `Span`).

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

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

### slice_from

```rust
fn slice_from(self: &Self, start: usize) -> Self
```

The elements from `start` to the end (C# `Slice(start)`).

Panics when `start` is outside the memory.

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

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

### slice

```rust
fn slice(self: &Self, start: usize, length: usize) -> Self
```

`length` elements starting at `start` (C# `Slice(start, length)`).

Panics when the range is outside the memory.

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

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

### offset_in_owner

```rust
fn offset_in_owner(self: &Self) -> usize
```

The offset of this memory inside its underlying buffer.

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

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

### owner

```rust
fn owner(self: &Self) -> Option<&Rc<[T]>>
```

The underlying buffer, when there is one.

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

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

### shares_owner_with

```rust
fn shares_owner_with(self: &Self, other: &Self) -> bool
```

Whether both memories view the same buffer (regardless of range).

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

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

### from_slice

```rust
fn from_slice(values: &[T]) -> Self
```

Copies a slice into a new shared buffer.

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

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

### to_vec

```rust
fn to_vec(self: &Self) -> Vec<T>
```

Copies the elements out (C# `ToArray`).

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

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

### from_str

```rust
fn from_str(text: &str) -> Self
```

Encodes a string as UTF-16 code units (C# `string.AsMemory()`).

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

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

### to_string_lossy

```rust
fn to_string_lossy(self: &Self) -> String
```

Decodes the UTF-16 code units, replacing lone surrogates with U+FFFD.

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

## Trait implementations

- `Send`
- `Sync`
- `Freeze`
- `UnsafeUnpin`
- `Unpin`
- `UnwindSafe`
- `RefUnwindSafe`
- [`PropertyValue`](/docs/0.5.0/api/ferroui-base/trait-propertyvalue/)
- [`AnyValue`](/docs/0.5.0/api/ferroui-base/trait-anyvalue/)
- [`ClassDefaults`](/docs/0.5.0/api/ferroui-base/trait-classdefaults/)
- `Borrow<T>`
- `BorrowMut<T>`
- `CloneToUninit`
- `Into<U>`
- `From<T>`
- `TryInto<U>`
- `TryFrom<U>`
- `Any`
- `ToOwned`
- `ErasedDestructor`
- `IntoEither`
- `Clone`
- `Default`
- `Debug`
- `PartialEq`
- `From<Vec<T>>`
- `From<Rc<[T]>>`
- `From<&str>`

## Availability

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