Struct kdb::List [−][src]
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]
&mut self,
index: I
) -> Option<&mut I::Output>
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.
fn index(&self, i: Range<usize>) -> &Self::Output
[src]
impl<T: KListable> Index<RangeFrom<usize>> for List<T>
[src]
type Output = [T::ListItem]
The returned type after indexing.
fn index(&self, i: RangeFrom<usize>) -> &Self::Output
[src]
impl<T: KListable> Index<RangeFull> for List<T>
[src]
type Output = [T::ListItem]
The returned type after indexing.
fn index(&self, _: RangeFull) -> &Self::Output
[src]
impl<T: KListable> Index<RangeTo<usize>> for List<T>
[src]
type Output = [T::ListItem]
The returned type after indexing.
fn index(&self, i: RangeTo<usize>) -> &Self::Output
[src]
impl<T: KListable> Index<usize> for List<T>
[src]
type Output = T::ListItem
The returned type after indexing.
fn index(&self, i: usize) -> &Self::Output
[src]
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]
T: KListable,
Auto Trait Implementations
impl<T> RefUnwindSafe for List<T> where
T: RefUnwindSafe,
[src]
T: RefUnwindSafe,
impl<T> !Send for List<T>
[src]
impl<T> !Sync for List<T>
[src]
impl<T> Unpin for List<T> where
T: Unpin,
[src]
T: Unpin,
impl<T> UnwindSafe for List<T> where
T: UnwindSafe,
[src]
T: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,