Skip to main content

ReadOnlyMemory

Struct ReadOnlyMemory 

Source
pub struct ReadOnlyMemory<T> { /* private fields */ }
Expand description

An immutable, reference counted slice of a shared buffer.

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

Implementations§

Source§

impl<T> ReadOnlyMemory<T>

Source

pub const fn empty() -> Self

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

Source

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

Wraps a whole shared buffer.

Source

pub 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

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

Takes ownership of a vector.

Source

pub fn len(&self) -> usize

The number of elements (C# Length).

Source

pub fn is_empty(&self) -> bool

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

Source

pub fn span(&self) -> &[T]

The elements (C# Span).

Source

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

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

Panics when start is outside the memory.

Source

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

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

Panics when the range is outside the memory.

Source

pub fn offset_in_owner(&self) -> usize

The offset of this memory inside its underlying buffer.

Source

pub fn owner(&self) -> Option<&Rc<[T]>>

The underlying buffer, when there is one.

Source

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

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

Source§

impl<T: Clone> ReadOnlyMemory<T>

Source

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

Copies a slice into a new shared buffer.

Source

pub fn to_vec(&self) -> Vec<T>

Copies the elements out (C# ToArray).

Source§

impl ReadOnlyMemory<u16>

Source

pub fn from_str(text: &str) -> Self

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

Source

pub fn to_string_lossy(&self) -> String

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

Trait Implementations§

Source§

impl<T> Clone for ReadOnlyMemory<T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for ReadOnlyMemory<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T> Default for ReadOnlyMemory<T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl From<&str> for ReadOnlyMemory<u16>

Source§

fn from(text: &str) -> Self

Converts to this type from the input type.
Source§

impl<T> From<Rc<[T]>> for ReadOnlyMemory<T>

Source§

fn from(values: Rc<[T]>) -> Self

Converts to this type from the input type.
Source§

impl<T> From<Vec<T>> for ReadOnlyMemory<T>

Source§

fn from(values: Vec<T>) -> Self

Converts to this type from the input type.
Source§

impl<T: PartialEq> PartialEq for ReadOnlyMemory<T>

Element-wise equality (unlike C#, where ReadOnlyMemory<T>.Equals compares the underlying object and range; use ReadOnlyMemory::shares_owner_with for that).

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more

Auto Trait Implementations§

§

impl<T> !Send for ReadOnlyMemory<T>

§

impl<T> !Sync for ReadOnlyMemory<T>

§

impl<T> Freeze for ReadOnlyMemory<T>
where Option<Rc<[T]>>: Freeze,

§

impl<T> RefUnwindSafe for ReadOnlyMemory<T>

§

impl<T> Unpin for ReadOnlyMemory<T>
where Option<Rc<[T]>>: Unpin,

§

impl<T> UnsafeUnpin for ReadOnlyMemory<T>

§

impl<T> UnwindSafe for ReadOnlyMemory<T>

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> AnyValue for T
where T: PartialEq + 'static,

Source§

fn any_value_as_any(&self) -> &(dyn Any + 'static)

Source§

fn any_value_eq(&self, other: &(dyn AnyValue + 'static)) -> bool

Source§

fn any_value_type_name(&self) -> &'static str

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> PropertyValue for T
where T: Clone + PartialEq + 'static,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.