Skip to main content

List

Struct List 

Source
pub struct List<T> {
    pub data: Vec<T>,
}
Expand description

A list provides fixed-width unit store.

identity: usize - 1-based integer (0 is the null sentinel) schema: usize - unit size in T error: ListError value: [T]

use context_engine::list::List;
use context_engine::required::SetOutcome;

let mut list: List<u32> = List::new(2);

// append: first real entry is id=1
let r = list.set(&0, &mut 2, &[10u32, 20], false).unwrap();
assert!(matches!(r, SetOutcome::Created(1)));
assert_eq!(list.get(&1, &2).unwrap(), &[10u32, 20]);

// update
let r = list.set(&1, &mut 2, &[30u32, 40], false).unwrap();
assert!(matches!(r, SetOutcome::Updated));
assert_eq!(list.get(&1, &2).unwrap(), &[30u32, 40]);

// delete then reuse_vacant
list.delete(&1, &mut 2).unwrap();
assert!(list.get(&1, &2).is_err());
let r = list.set(&0, &mut 2, &[50u32, 60], true).unwrap();
assert!(matches!(r, SetOutcome::Created(1)));

Fields§

§data: Vec<T>

Implementations§

Source§

impl<T: Copy + Default + PartialEq> List<T>

Source

pub fn new(width: usize) -> Self

Source§

impl<T: Copy + Default + PartialEq> List<T>

Source

pub fn get<'a>( &'a self, identity: &usize, schema: &usize, ) -> Result<&'a [T], ListError>

Source

pub fn set( &mut self, identity: &usize, schema: &mut usize, value: &[T], reuse_vacant: bool, ) -> Result<SetOutcome, ListError>

intern: if true and identity=0, return first match value identity(i)

Source

pub fn delete( &mut self, identity: &usize, schema: &mut usize, ) -> Result<(), ListError>

Auto Trait Implementations§

§

impl<T> Freeze for List<T>

§

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

§

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

§

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

§

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

§

impl<T> UnsafeUnpin for List<T>

§

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> 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, 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.