tvm_ffi::collections::list

Struct List

Source
#[repr(C)]
pub struct List<T> { /* private fields */ }
Expand description

Mutable, reference-counted sequence of T, sharing its underlying ListObj with C++. Cloning is cheap (it bumps the refcount) and yields a handle to the same list.

Implementations§

Source§

impl<T: ContainerElement> List<T>

Source

pub fn new() -> Self

Creates a new, empty list (via an ffi.List() call to the C++ runtime).

Source

pub fn len(&self) -> usize

Returns the number of elements.

Source

pub fn is_empty(&self) -> bool

Returns true if the list contains no elements.

Source

pub fn capacity(&self) -> usize

Returns the number of elements the buffer holds before it is reallocated.

Source

pub fn get(&self, index: usize) -> Result<T>

Returns the element at index.

Source

pub fn set(&self, index: usize, value: T) -> Result<()>

Replaces the element at index.

Source

pub fn push(&self, value: T) -> Result<()>

Appends value to the end of the list.

Source

pub fn insert(&self, index: usize, value: T) -> Result<()>

Inserts value at index, shifting the elements after it.

Source

pub fn remove(&self, index: usize) -> Result<T>

Removes and returns the element at index, shifting the elements after it. If that element is not a T, the list is left untouched.

Source

pub fn clear(&self)

Removes all elements, keeping the buffer.

Source

pub fn first(&self) -> Result<T>

Returns the first element, or an INDEX_ERROR if the list is empty.

Source

pub fn last(&self) -> Result<T>

Returns the last element, or an INDEX_ERROR if the list is empty.

Source

pub fn pop(&self) -> Result<T>

Removes and returns the last element, or an INDEX_ERROR if the list is empty.

Source

pub fn truncate(&self, len: usize)

Shortens the list to len elements, dropping the rest; a no-op when it is already that short. C++ resize when shrinking.

Source

pub fn remove_range(&self, start: usize, end: usize) -> Result<()>

Removes the elements in start..end, shifting the ones after them.

Source

pub fn insert_many<I: IntoIterator<Item = T>>( &self, index: usize, iter: I, ) -> Result<()>

Inserts every item of iter, in order, at index, shifting the elements after it. C++ insert(position, first, last).

Source

pub fn reserve(&self, additional: usize) -> Result<()>

Makes room for at least additional more elements without reallocating again, like Vec::reserve. C++ reserve(n) takes the absolute capacity instead.

Source

pub fn extend<I: IntoIterator<Item = T>>(&self, iter: I) -> Result<()>

Appends every item of iter, in order.

Source

pub fn resize(&self, new_len: usize, value: T) -> Result<()>
where T: Clone,

Resizes the list to new_len elements, dropping the tail or appending clones of value. C++ resize.

Source

pub fn reverse(&self)

Reverses the elements in place. C++ Reverse.

Source

pub fn iter(&self) -> ListIterator<'_, T> ⓘ

Returns a double-ended iterator over the elements, yielding Result<T>; see ListIterator.

Trait Implementations§

Source§

impl<T: ContainerElement> AnyCompatible for List<T>

Source§

unsafe fn is_undefined(field: *const Self) -> bool

Whether field, which holds a value of this type or all-zero bytes, holds all-zero bytes that are no value of this type, as a null object reference, a string of type index None or a zero device type: a field that a creator left undefined for reflection to set, as C++ UnsafeInit leaves a reference undefined (null). Unlike a C++ undefined reference, it is no value; a nullable reference is Option<T>, whose None is a defined value. Read more
Source§

fn type_str() -> String

the type string of the type
Source§

fn type_schema() -> String

The type schema of the type: the JSON object C++ TypeTraits<T>::TypeSchema writes, which the type schemas of functions and fields embed. Read more
Source§

unsafe fn check_any_strict(data: &TVMFFIAny) -> bool

Source§

unsafe fn copy_to_any_view(src: &Self, data: &mut TVMFFIAny)

the value to copy to TVMFFIAny
Source§

unsafe fn move_to_any(src: Self, data: &mut TVMFFIAny)

consume the value to move to Any
Source§

unsafe fn copy_from_any_view_after_check(data: &TVMFFIAny) -> Self

Copy value from TVMFFIAny after checking caller must ensure that the value is compatible with the type
Source§

unsafe fn move_from_any_after_check(data: &mut TVMFFIAny) -> Self

the value to move from TVMFFIAny NOTE: pay very careful attention to avoid memory leak! Read more
Source§

unsafe fn try_cast_from_any_view(data: &TVMFFIAny) -> Result<Self, ()>

try to cast the value from AnyView
Source§

fn get_mismatch_type_info(data: &TVMFFIAny) -> String

Get the type key of a type when TryCastFromAnyView fails.
Source§

fn to_any(&self) -> Any

Borrow self into an owned Any, increfing object-backed values. Read more
Source§

impl<T: ContainerElement> ArgIntoRef for &List<T>

Source§

type Target = List<T>

Source§

fn to_ref(&self) -> &Self::Target

Source§

impl<T: ContainerElement> ArgIntoRef for List<T>

Source§

type Target = List<T>

Source§

fn to_ref(&self) -> &Self::Target

Source§

impl<T> Clone for List<T>

Source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<T> Debug for List<T>

Source§

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

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

impl<T: ContainerElement> Default for List<T>

Source§

fn default() -> Self

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

impl<T: ContainerElement> FromIterator<T> for List<T>

Source§

fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self

Creates a value from an iterator. Read more
Source§

impl<'a, T: ContainerElement> IntoArgHolder for &'a List<T>

Source§

type Target = &'a List<T>

Source§

fn into_arg_holder(self) -> Self::Target

Source§

impl<T: ContainerElement> IntoArgHolder for List<T>

Source§

impl<'a, T: ContainerElement> IntoIterator for &'a List<T>

Source§

type Item = Result<T, Error>

The type of the elements being iterated over.
Source§

type IntoIter = ListIterator<'a, T>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<T> ObjectRefCore for List<T>

Source§

type ContainerType = ListObj

Source§

fn data(this: &Self) -> &ObjectArc<ListObj>

Source§

fn into_data(this: Self) -> ObjectArc<ListObj>

Source§

unsafe fn from_data(data: ObjectArc<ListObj>) -> Self

Construct a reference view from an owning container handle. Read more
Source§

fn same_as<Other: ObjectRefCore>(&self, other: &Other) -> bool

Return whether two object references point to the same allocation.
Source§

fn downcast_ref<T: ObjectCore>(&self) -> Option<&T>

Borrow the underlying object as T when its runtime type is T or a subtype. Read more
Source§

impl<T: ContainerElement> TryFrom<Any> for List<T>

Source§

type Error = Error

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

fn try_from(value: Any) -> Result<Self>

Performs the conversion.
Source§

impl<'a, T: ContainerElement> TryFrom<AnyView<'a>> for List<T>

Source§

type Error = Error

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

fn try_from(value: AnyView<'a>) -> Result<Self>

Performs the conversion.

Auto Trait Implementations§

§

impl<T> Freeze for List<T>

§

impl<T> RefUnwindSafe for List<T>
where T: RefUnwindSafe,

§

impl<T> !Send for List<T>

§

impl<T> !Sync for List<T>

§

impl<T> Unpin for List<T>
where T: Unpin,

§

impl<T> UnwindSafe for List<T>
where T: UnwindSafe,

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

Source§

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

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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> ObjectRefCast for T

Source§

fn try_cast<B>(self) -> Result<B>

Consume self and rewrap the underlying object as B without copying.
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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.