Struct kdb::List[][src]

#[repr(transparent)]pub struct List<T> { /* fields omitted */ }

Lists are the KDB equivalent of Rust's Vec. They contain collections of values and their contents be looked up by index.

Examples

use kdb::{KBox, List, list};

let mut l = list![i32; 1, 2, 3, 4, 5];
l.push(6);
let sl = &l[..]; // we can take slices and use them like other rust slices.
assert_eq!(21, sl.iter().copied().sum());

Appending to lists

When you append to lists in KDB, it will potentially reallocate the raw list which gives you a new and different pointer. So you can only extend lists safely if you own them, which means methods like push and join are only available on types of KBox<List<_>>.

You Notes for best performance: using list! or .collect() to create a populated list will typically result in better performance than using new and push. This is because they will, where possible, allocate a list large enough for all items up front. push will reallocate whenever needed.

Implementations

impl<T: KListable> List<T>[src]

pub fn as_slice(&self) -> &[T::ListItem][src]

Returns the contents of the list as a slice

pub fn as_slice_mut(&mut self) -> &mut [T::ListItem][src]

Returns the contents of the list as a mutable slice

pub fn iter(&self) -> Iter<'_, T::ListItem>[src]

Returns an iterator over the list.

pub fn len(&self) -> usize[src]

Returns the number of elements in the list.

pub fn is_empty(&self) -> bool[src]

Returns true if the list has a length of 0.

pub fn iter_mut(&mut self) -> IterMut<'_, T::ListItem>[src]

Returns an iterator that allows modifying each value.

pub fn get<I: SliceIndex<[T::ListItem]>>(&self, index: I) -> Option<&I::Output>[src]

Returns a reference to an element or a subslice, depending on the type of index.

pub fn get_mut<I: SliceIndex<[T::ListItem]>>(
    &mut self,
    index: I
) -> Option<&mut I::Output>
[src]

Returns a mutable reference to an element or a subslice, depending on the type of index.

impl List<i8>[src]

pub fn try_as_str(&self) -> Result<&str, ConversionError>[src]

Attempts to convert to a valid utf-8 string. This will return an error if the string contains invalid utf-8 characters. This function does not allocate.

pub unsafe fn as_str_unchecked(&self) -> &str[src]

Converts the symbol to a rust str without checking if it is valid.

Safety

The string must be valid UTF-8. It's length must be less than or equal to isize::MAX.

Trait Implementations

impl<T: KListable> AsRef<Any> for List<T>[src]

impl<T: KListable> Index<Range<usize>> for List<T>[src]

type Output = [T::ListItem]

The returned type after indexing.

impl<T: KListable> Index<RangeFrom<usize>> for List<T>[src]

type Output = [T::ListItem]

The returned type after indexing.

impl<T: KListable> Index<RangeFull> for List<T>[src]

type Output = [T::ListItem]

The returned type after indexing.

impl<T: KListable> Index<RangeTo<usize>> for List<T>[src]

type Output = [T::ListItem]

The returned type after indexing.

impl<T: KListable> Index<usize> for List<T>[src]

type Output = T::ListItem

The returned type after indexing.

impl<T: KListable> IndexMut<Range<usize>> for List<T>[src]

impl<T: KListable> IndexMut<RangeFrom<usize>> for List<T>[src]

impl<T: KListable> IndexMut<RangeFull> for List<T>[src]

impl<T: KListable> IndexMut<RangeTo<usize>> for List<T>[src]

impl<T: KListable> IndexMut<usize> for List<T>[src]

impl<T> TryFrom<&'_ Any> for &List<T> where
    T: KListable, 
[src]

type Error = ConversionError

The type returned in the event of a conversion error.

Auto Trait Implementations

impl<T> RefUnwindSafe for List<T> where
    T: RefUnwindSafe
[src]

impl<T> !Send for List<T>[src]

impl<T> !Sync for List<T>[src]

impl<T> Unpin for List<T> where
    T: Unpin
[src]

impl<T> UnwindSafe for List<T> where
    T: UnwindSafe
[src]

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.