Skip to main content

List

Struct List 

Source
pub struct List { /* private fields */ }
Expand description

A list: a finite sequence, in order.

Implementations§

Source§

impl List

Source

pub fn new() -> Self

Returns the empty list.

Source

pub fn parts(&self) -> ListParts<'_>

Returns what the list is made of: the list is front, then the elements of tree it takes, then back.

The front and the back hold at most eight elements each. A list of more than eight whose ends do not hold all of it has a tree, and one of at most eight has none and holds everything at its back.

Source

pub fn tree(&self) -> Option<Node>

Returns the whole list as one balanced tree, or None when it is empty: its front, the elements it takes from its tree and its back, joined. The tree shares every node of the list’s own that the cut and the joins do not pass through, so it costs O(log n) new nodes.

Source

pub fn from_parts( front: Vec<Value>, tree: Option<(Node, usize, usize)>, back: Vec<Value>, ) -> Result<List, StructureError>

Returns the list of front, then the taken elements of tree that follow its first skip, then back, sharing tree.

The list’s measure is that of its ends and of the window, which the tree’s nodes record, so this costs O(EDGE + log n) whatever the tree holds, but for a list of at most eight elements, which keeps no tree and is copied out of it.

§Errors

StructureError::End when an end holds more than eight elements, and StructureError::Window when the tree does not hold skip + taken elements.

Source

pub fn len(&self) -> usize

Returns how many elements there are.

Source

pub fn is_empty(&self) -> bool

Returns whether there are none.

Source

pub fn get(&self, index: usize) -> Option<&Value>

Returns the element at a zero-based position.

Source

pub fn get_int(&self, index: &Int) -> Option<&Value>

Returns the element at a zero-based Int position: None for a negative one or one not less than the length (list.get).

Source

pub fn iter( &self, ) -> impl DoubleEndedIterator<Item = &Value> + ExactSizeIterator

Returns the elements, in order.

Source

pub fn slice(&self, start: usize, end: usize) -> Option<List>

Returns the elements from start up to, not including, end, sharing this list’s tree, or None unless start ≤ end ≤ length.

Source

pub fn push_back(self, item: Value) -> List

Returns self with item added at the end.

Source

pub fn push_front(self, item: Value) -> List

Returns self with item added at the front.

Source

pub fn concat(self, other: List) -> List

Returns self + other, sharing both lists’ trees.

Source

pub fn sort_by_keys(&self, keys: &[Value]) -> Result<Option<List>, DataError>

Returns items reordered by keys, one key per item, stably: items whose keys are equal keep their order (list.sort_by).

Returns None when there is not exactly one key per item.

§Errors

A DataError when two keys cannot be compared: one is not data, or the two are of different shapes.

Trait Implementations§

Source§

impl Clone for List

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 Debug for List

Source§

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

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

impl Default for List

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Drop for List

Dropping a list drops its ends and the nodes of its tree that nothing else holds, and hands the elements in them to dismantle in the value module, so a deep value drops without deep recursion.

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl FromIterator<Value> for List

Source§

fn from_iter<I: IntoIterator<Item = Value>>(items: I) -> Self

Creates a value from an iterator. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for List

§

impl !UnwindSafe for List

§

impl Forget for List

§

impl Freeze for List
where *const ArcInner<Vec<Value>> is !null: Freeze, PhantomData<ArcInner<Vec<Value>>>: Freeze, *const ArcInner<Inner<Value>> is !null: Freeze, PhantomData<ArcInner<Inner<Value>>>: Freeze,

§

impl Move for List

§

impl Send for List
where Arc<Vec<Value>>: Send, Arc<Inner<Value>>: Send,

§

impl Sync for List
where Arc<Vec<Value>>: Sync, Arc<Inner<Value>>: Sync,

§

impl Unpin for List
where Arc<Vec<Value>>: Unpin, Arc<Inner<Value>>: Unpin,

§

impl UnsafeUnpin for List
where *const ArcInner<Vec<Value>> is !null: UnsafeUnpin, PhantomData<ArcInner<Vec<Value>>>: UnsafeUnpin, *const ArcInner<Inner<Value>> is !null: UnsafeUnpin, PhantomData<ArcInner<Inner<Value>>>: UnsafeUnpin,

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.