ReadOnlyMemory
struct · ferroui-base · v0.5.0
struct ReadOnlyMemory<T>
An immutable, reference counted slice of a shared buffer.
Cloning and slicing never copy the elements; they bump one reference count.
Members
emptynewwith_rangefrom_veclenis_emptyspanslice_fromsliceoffset_in_ownerownershares_owner_withfrom_sliceto_vecfrom_strto_string_lossy
empty
const fn empty() -> Self
The empty memory (C# default / ReadOnlyMemory<T>.Empty).
new
fn new(owner: Rc<[T]>) -> Self
Wraps a whole shared buffer.
with_range
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.
from_vec
fn from_vec(values: Vec<T>) -> Self
Takes ownership of a vector.
len
fn len(self: &Self) -> usize
The number of elements (C# Length).
is_empty
fn is_empty(self: &Self) -> bool
Whether the memory has no elements (C# IsEmpty).
span
fn span(self: &Self) -> &[T]
The elements (C# Span).
slice_from
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.
slice
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.
offset_in_owner
fn offset_in_owner(self: &Self) -> usize
The offset of this memory inside its underlying buffer.
owner
fn owner(self: &Self) -> Option<&Rc<[T]>>
The underlying buffer, when there is one.
shares_owner_with
fn shares_owner_with(self: &Self, other: &Self) -> bool
Whether both memories view the same buffer (regardless of range).
from_slice
fn from_slice(values: &[T]) -> Self
Copies a slice into a new shared buffer.
to_vec
fn to_vec(self: &Self) -> Vec<T>
Copies the elements out (C# ToArray).
from_str
fn from_str(text: &str) -> Self
Encodes a string as UTF-16 code units (C# string.AsMemory()).
to_string_lossy
fn to_string_lossy(self: &Self) -> String
Decodes the UTF-16 code units, replacing lone surrogates with U+FFFD.
Trait implementations
SendSyncFreezeUnsafeUnpinUnpinUnwindSafeRefUnwindSafePropertyValueAnyValueClassDefaultsBorrow<T>BorrowMut<T>CloneToUninitInto<U>From<T>TryInto<U>TryFrom<U>AnyToOwnedErasedDestructorIntoEitherCloneDefaultDebugPartialEqFrom<Vec<T>>From<Rc<[T]>>From<&str>
Availability
Extracted for aarch64-apple-darwin. Cargo features are listed in the crate index.