pub struct List<T> { /* private fields */ }Expand description
A mutable, reference-counted sequence of T, passed across languages as
ffi.List.
Cloning a List is cheap and yields a handle to the same list, so a change
through one handle is seen through every other. Methods take &self.
§Examples
use tvm_ffi::List;
let list = List::<i64>::new();
list.push(1)?;
list.push(2)?;
assert_eq!(list.get(1)?, 2);
assert_eq!(list.len(), 2);Implementations§
Source§impl<T: ContainerElement> List<T>
impl<T: ContainerElement> List<T>
Sourcepub fn capacity(&self) -> usize
pub fn capacity(&self) -> usize
Returns the number of elements the buffer holds before it is reallocated.
Sourcepub fn insert(&self, index: usize, value: T) -> Result<()>
pub fn insert(&self, index: usize, value: T) -> Result<()>
Inserts value at index, shifting the elements after it.
Sourcepub fn remove(&self, index: usize) -> Result<T>
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.
Sourcepub fn first(&self) -> Result<Option<T>>
pub fn first(&self) -> Result<Option<T>>
Returns the first element, or None if the list is empty; a
TYPE_ERROR as get gives it.
Sourcepub fn last(&self) -> Result<Option<T>>
pub fn last(&self) -> Result<Option<T>>
Returns the last element, or None if the list is empty; a
TYPE_ERROR as get gives it.
Sourcepub fn pop(&self) -> Result<Option<T>>
pub fn pop(&self) -> Result<Option<T>>
Removes and returns the last element, or None if the list is empty;
a TYPE_ERROR as remove gives it.
Sourcepub fn truncate(&self, len: usize)
pub fn truncate(&self, len: usize)
Shortens the list to len elements, dropping the rest; a no-op when it
is already that short.
Sourcepub fn remove_range(&self, range: impl RangeBounds<usize>)
pub fn remove_range(&self, range: impl RangeBounds<usize>)
Removes the elements in range, shifting the ones after them, as
Vec::drain does without returning them.
§Panics
Panics if range starts after it ends or ends past the list.
Sourcepub fn insert_many<I: IntoIterator<Item = T>>(
&self,
index: usize,
iter: I,
) -> Result<()>
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.
Sourcepub fn reserve(&self, additional: usize) -> Result<()>
pub fn reserve(&self, additional: usize) -> Result<()>
Makes room for at least additional more elements without
reallocating again, like Vec::reserve.
Sourcepub fn extend<I: IntoIterator<Item = T>>(&self, iter: I) -> Result<()>
pub fn extend<I: IntoIterator<Item = T>>(&self, iter: I) -> Result<()>
Appends every item of iter, in order.
Trait Implementations§
Source§impl<T: ContainerElement> AnyCompatible for List<T>
impl<T: ContainerElement> AnyCompatible for List<T>
Source§unsafe fn is_undefined(field: *const Self) -> bool
unsafe fn is_undefined(field: *const Self) -> bool
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. An undefined field
is no value; a nullable reference is Option<T>, whose None is a
defined value. Read moreSource§fn type_str() -> String
fn type_str() -> String
int,
ffi.String or Array<int>.Source§fn type_schema() -> String
fn type_schema() -> String
Source§unsafe fn check_any_strict(data: &TVMFFIAny) -> bool
unsafe fn check_any_strict(data: &TVMFFIAny) -> bool
Source§unsafe fn copy_to_any_view(src: &Self, data: &mut TVMFFIAny)
unsafe fn copy_to_any_view(src: &Self, data: &mut TVMFFIAny)
Source§unsafe fn move_to_any(src: Self, data: &mut TVMFFIAny)
unsafe fn move_to_any(src: Self, data: &mut TVMFFIAny)
Source§unsafe fn copy_from_any_view_after_check(data: &TVMFFIAny) -> Self
unsafe fn copy_from_any_view_after_check(data: &TVMFFIAny) -> Self
Self out of a cell that holds one, retaining any object. Read moreSource§unsafe fn move_from_any_after_check(data: &mut TVMFFIAny) -> Self
unsafe fn move_from_any_after_check(data: &mut TVMFFIAny) -> Self
Self out of an owning cell that holds one. Read moreSource§unsafe fn try_cast_from_any_view(data: &TVMFFIAny) -> Result<Self, ()>
unsafe fn try_cast_from_any_view(data: &TVMFFIAny) -> Result<Self, ()>
data into a Self by the FFI rules, such as an integer into a
float; Err if it does not convert. Read moreSource§fn get_mismatch_type_info(data: &TVMFFIAny) -> String
fn get_mismatch_type_info(data: &TVMFFIAny) -> String
data in conversion errors; by
default its runtime type key.Source§impl<T: ContainerElement> Default for List<T>
impl<T: ContainerElement> Default for List<T>
Source§impl<T> DowncastRefFromAny for List<T>where
T: ContainerElement,
impl<T> DowncastRefFromAny for List<T>where
T: ContainerElement,
Source§impl<T: ContainerElement> FromIterator<T> for List<T>
impl<T: ContainerElement> FromIterator<T> for List<T>
Source§fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self
fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self
Source§impl<'a, T: ContainerElement> IntoIterator for &'a List<T>
impl<'a, T: ContainerElement> IntoIterator for &'a List<T>
Source§impl<T: ContainerElement> ObjectRefCore for List<T>
impl<T: ContainerElement> ObjectRefCore for List<T>
Source§type ContainerType = ListObj
type ContainerType = ListObj
Source§unsafe fn from_data(data: ObjectArc<ListObj>) -> Self
unsafe fn from_data(data: ObjectArc<ListObj>) -> Self
Source§fn same_as<Other: ObjectRefCore>(&self, other: &Other) -> bool
fn same_as<Other: ObjectRefCore>(&self, other: &Other) -> bool
Source§fn type_key(&self) -> &'static str
fn type_key(&self) -> &'static str
"ffi.Array", as C++ ObjectRef::GetTypeKey.Source§fn is<T: AnyCompatible>(&self) -> bool
fn is<T: AnyCompatible>(&self) -> bool
T as is, such as a subtype or a container
whose elements are checked too, by the strict check of
downcast, without a reference count change.
See also crate::Any::is.