Skip to main content

List

Struct List 

Source
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>

Source

pub fn new() -> Self

Creates an empty list.

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)

Replaces the element at index, as vec[index] = value.

§Panics

Panics if index >= len.

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<Option<T>>

Returns the first element, or None if the list is empty; a TYPE_ERROR as get gives it.

Source

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.

Source

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.

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.

Source

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.

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.

Source

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

Makes room for at least additional more elements without reallocating again, like Vec::reserve.

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.

Source

pub fn reverse(&self)

Reverses the elements in place.

Source

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

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

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. An undefined field is no value; a nullable reference is Option<T>, whose None is a defined value. Read more
Source§

fn type_str() -> String

The type name in conversion errors and type schemas, such as int, ffi.String or Array<int>.
Source§

fn type_schema() -> String

The type schema of the type: the JSON object that describes it, which the type schemas of functions and fields embed. Read more
Source§

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

Whether data holds a Self as is, without conversion. Read more
Source§

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

Write a cell that borrows src into data. Read more
Source§

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

Write a cell that owns src into data. Read more
Source§

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

Copy a Self out of a cell that holds one, retaining any object. Read more
Source§

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

Move a Self out of an owning cell that holds one. Read more
Source§

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

Convert data into a Self by the FFI rules, such as an integer into a float; Err if it does not convert. Read more
Source§

fn get_mismatch_type_info(data: &TVMFFIAny) -> String

The name of the mismatched value data in conversion errors; by default its runtime type key.
Source§

fn to_any(&self) -> Any

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

impl<T> Clone for List<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 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> Display for List<T>

Formats the list as its repr; see AnyView.

Source§

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

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

impl<T> DowncastRefFromAny for List<T>

Source§

unsafe fn downcast_ref_from_any(cell: &TVMFFIAny) -> Option<&Self>

Borrow cell as Self when it holds one. Read more
Source§

impl<T: ContainerElement> From<List<T>> for ObjectRef

A list upcasts to the root ObjectRef.

Source§

fn from(value: List<T>) -> Self

Converts to this type from the input type.
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<T: ContainerElement> IntoArg<List<T>> for List<T>

Source§

type Output = List<T>

T when owned, &T when borrowed.
Source§

fn into_arg(self) -> List<T>

Convert into a T or a &T.
Source§

fn into_owned(self) -> List<T>

Convert into an owned T, cloning only a borrowed value.
Source§

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

Source§

type Output = &'a List<T>

T when owned, &T when borrowed.
Source§

fn into_arg(self) -> &'a List<T>

Convert into a T or a &T.
Source§

fn into_owned(self) -> List<T>

Convert into an owned T, cloning only a borrowed value.
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 = Iter<'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: ContainerElement> ObjectRefCore for List<T>

Source§

type ContainerType = ListObj

The object type the reference points to.
Source§

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

Borrow the object’s handle.
Source§

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

Take the object’s handle.
Source§

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

Make a reference from the object’s handle. Read more
Source§

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

Whether two references point to the same object.
Source§

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

The registered type key of the object’s runtime type, such as "ffi.Array", as C++ ObjectRef::GetTypeKey.
Source§

fn is<T: AnyCompatible>(&self) -> bool

Whether the reference is a 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.
Source§

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

Borrow the underlying object as T when it is one. Read more
Source§

fn downcast<B>(self) -> Result<B, Self>
where B: ObjectRefCore,

Take self as B, a subtype or a container such as Array<i64> whose elements are checked too, when its object is one, without copying it. On a mismatch the reference is returned unchanged. Read more
Source§

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

Source§

type Holder = List<T>

What keeps the argument alive during the call.
Source§

fn into_packed_arg(self) -> List<T>

Source§

fn as_packed_arg(holder: &Self::Holder) -> AnyView<'_>

Source§

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

Source§

type Holder = &'a List<T>

What keeps the argument alive during the call.
Source§

fn into_packed_arg(self) -> &'a List<T>

Source§

fn as_packed_arg(holder: &Self::Holder) -> AnyView<'_>

Source§

impl<'b, T: ContainerElement> TryFrom<&'b Any> for List<T>

Source§

type Error = Error

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

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

Performs the conversion.
Source§

impl<T: ContainerElement> TryFrom<&ObjectRef> for List<T>

Source§

type Error = Error

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

fn try_from(value: &ObjectRef) -> Result<Self>

Performs the conversion.
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.
Source§

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

The strict downcast from the root ObjectRef.

Source§

type Error = Error

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

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

Performs the conversion.

Auto Trait Implementations§

§

impl<T> !RefUnwindSafe for List<T>

§

impl<T> !Send for List<T>

§

impl<T> !Sync for List<T>

§

impl<T> !UnwindSafe for List<T>

§

impl<T> Freeze for List<T>

§

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

§

impl<T> UnsafeUnpin for List<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> 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, 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> ContainerElement for T
where T: AnyCompatible,

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> 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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.
Source§

impl<T> TypeSubsumes<T> for T
where T: ?Sized,