[][src]Struct exonum_merkledb::indexes::ListIndex

pub struct ListIndex<T: RawAccess, V> { /* fields omitted */ }

A list of items where elements are added to the end of the list and are removed starting from the end of the list.

Access to the elements is obtained using the indexes of the list items. ListIndex implements an array list, storing the elements as values and using u64 as an index. ListIndex requires that elements implement the BinaryValue trait.

Methods

impl<T, V> ListIndex<T, V> where
    T: RawAccess,
    V: BinaryValue
[src]

pub fn get(&self, index: u64) -> Option<V>[src]

Returns an element at the indicated position or None if the indicated position is out of bounds.

Examples

use exonum_merkledb::{access::CopyAccessExt, TemporaryDB, Database, ListIndex};

let db = TemporaryDB::new();
let fork = db.fork();
let mut index = fork.get_list("name");
assert_eq!(None, index.get(0));

index.push(42);
assert_eq!(Some(42), index.get(0));

pub fn last(&self) -> Option<V>[src]

Returns the last element of the list or None if the list is empty.

Examples

use exonum_merkledb::{access::CopyAccessExt, TemporaryDB, Database, ListIndex};

let db = TemporaryDB::new();
let fork = db.fork();
let mut index = fork.get_list("name");
assert_eq!(None, index.last());

index.push(42);
assert_eq!(Some(42), index.last());

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

Returns true if the list contains no elements.

Examples

use exonum_merkledb::{access::CopyAccessExt, TemporaryDB, Database, ListIndex};

let db = TemporaryDB::new();
let fork = db.fork();
let mut index = fork.get_list("name");
assert!(index.is_empty());

index.push(42);
assert!(!index.is_empty());

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

Returns the number of elements in the list.

Examples

use exonum_merkledb::{access::CopyAccessExt, TemporaryDB, Database, ListIndex};

let db = TemporaryDB::new();
let fork = db.fork();
let mut index = fork.get_list("name");
assert_eq!(0, index.len());

index.push(10);
assert_eq!(1, index.len());

index.push(100);
assert_eq!(2, index.len());

pub fn iter(&self) -> Values<V>[src]

Returns an iterator over the list values.

Examples

use exonum_merkledb::{access::CopyAccessExt, TemporaryDB, Database, ListIndex};

let db = TemporaryDB::new();
let fork = db.fork();
let mut index = fork.get_list("name");

index.extend([1, 2, 3, 4, 5].iter().cloned());

for val in index.iter() {
    println!("{}", val);
}

pub fn iter_from(&self, from: u64) -> Values<V>[src]

Returns an iterator over the list values starting from the specified position.

Examples

use exonum_merkledb::{access::CopyAccessExt, TemporaryDB, Database, ListIndex};

let db = TemporaryDB::new();
let fork = db.fork();
let mut index = fork.get_list("name");

index.extend([1, 2, 3, 4, 5].iter().cloned());

for val in index.iter_from(3) {
    println!("{}", val);
}

impl<T, V> ListIndex<T, V> where
    T: RawAccessMut,
    V: BinaryValue
[src]

pub fn push(&mut self, value: V)[src]

Appends an element to the back of the list.

Examples

use exonum_merkledb::{access::CopyAccessExt, TemporaryDB, Database, ListIndex};

let db = TemporaryDB::new();
let fork = db.fork();
let mut index = fork.get_list("name");

index.push(1);
assert!(!index.is_empty());

pub fn pop(&mut self) -> Option<V>[src]

Removes the last element from the list and returns it, or returns None if the list is empty.

Examples

use exonum_merkledb::{access::CopyAccessExt, TemporaryDB, Database, ListIndex};

let db = TemporaryDB::new();
let fork = db.fork();
let mut index = fork.get_list("name");

assert_eq!(None, index.pop());
index.push(1);
assert_eq!(Some(1), index.pop());

pub fn extend<I>(&mut self, iter: I) where
    I: IntoIterator<Item = V>, 
[src]

Extends the list with the contents of an iterator.

Examples

use exonum_merkledb::{access::CopyAccessExt, TemporaryDB, Database, ListIndex};

let db = TemporaryDB::new();
let fork = db.fork();
let mut index = fork.get_list("name");
assert!(index.is_empty());

index.extend([1, 2, 3].iter().cloned());
assert_eq!(3, index.len());

pub fn truncate(&mut self, len: u64)[src]

Shortens the list, keeping the indicated number of first len elements and dropping the rest.

If len is greater than the current state of the list, this has no effect.

Examples

use exonum_merkledb::{access::CopyAccessExt, TemporaryDB, Database, ListIndex};

let db = TemporaryDB::new();
let fork = db.fork();
let mut index = fork.get_list("name");

index.extend([1, 2, 3, 4, 5].iter().cloned());
assert_eq!(5, index.len());
index.truncate(3);
assert_eq!(3, index.len());

pub fn set(&mut self, index: u64, value: V)[src]

Changes a value at the specified position.

Panics

Panics if the indicated position (index) is equal to or greater than the current state of the list.

Examples

use exonum_merkledb::{access::CopyAccessExt, TemporaryDB, Database, ListIndex};

let db = TemporaryDB::new();
let fork = db.fork();
let mut index = fork.get_list("name");

index.push(1);
assert_eq!(Some(1), index.get(0));

index.set(0, 10);
assert_eq!(Some(10), index.get(0));

pub fn clear(&mut self)[src]

Clears the list, removing all values.

Notes

Currently, this method is not optimized to delete a large set of data. During the execution of this method, the amount of allocated memory is linearly dependent on the number of elements in the index.

Examples

use exonum_merkledb::{access::CopyAccessExt, TemporaryDB, Database, ListIndex};

let db = TemporaryDB::new();
let fork = db.fork();
let mut index = fork.get_list("name");

index.push(1);
assert!(!index.is_empty());

index.clear();
assert!(index.is_empty());

Trait Implementations

impl<T: Debug + RawAccess, V: Debug> Debug for ListIndex<T, V>[src]

impl<T, V> FromAccess<T> for ListIndex<T::Base, V> where
    T: Access,
    V: BinaryValue
[src]

impl<T, V> IndexIterator for ListIndex<T, V> where
    T: RawAccess,
    V: BinaryValue
[src]

type Key = u64

Type encompassing index keys.

type Value = V

Type encompassing index values.

impl<'a, T, V> IntoIterator for &'a ListIndex<T, V> where
    T: RawAccess,
    V: BinaryValue
[src]

type Item = V

The type of the elements being iterated over.

type IntoIter = Values<'a, V>

Which kind of iterator are we turning this into?

Auto Trait Implementations

impl<T, V> RefUnwindSafe for ListIndex<T, V> where
    T: RefUnwindSafe,
    V: RefUnwindSafe,
    <T as RawAccess>::Changes: RefUnwindSafe

impl<T, V> Send for ListIndex<T, V> where
    T: Send,
    V: Send,
    <T as RawAccess>::Changes: Send

impl<T, V> Sync for ListIndex<T, V> where
    T: Sync,
    V: Sync,
    <T as RawAccess>::Changes: Sync

impl<T, V> Unpin for ListIndex<T, V> where
    T: Unpin,
    V: Unpin,
    <T as RawAccess>::Changes: Unpin

impl<T, V> UnwindSafe for ListIndex<T, V> where
    T: UnwindSafe,
    V: UnwindSafe,
    <T as RawAccess>::Changes: UnwindSafe

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.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,