snarkvm_ledger_store::helpers

Trait MapRead

Source
pub trait MapRead<'a, K: 'a + Copy + Clone + PartialEq + Eq + Hash + Serialize + Deserialize<'a> + Sync, V: 'a + Clone + PartialEq + Eq + Serialize + Deserialize<'a> + Sync> {
    type PendingIterator: Iterator<Item = (Cow<'a, K>, Option<Cow<'a, V>>)>;
    type Iterator: Iterator<Item = (Cow<'a, K>, Cow<'a, V>)>;
    type Keys: Iterator<Item = Cow<'a, K>>;
    type Values: Iterator<Item = Cow<'a, V>>;

    // Required methods
    fn len_confirmed(&self) -> usize;
    fn contains_key_confirmed<Q>(&self, key: &Q) -> Result<bool>
       where K: Borrow<Q>,
             Q: PartialEq + Eq + Hash + Serialize + ?Sized;
    fn contains_key_speculative<Q>(&self, key: &Q) -> Result<bool>
       where K: Borrow<Q>,
             Q: PartialEq + Eq + Hash + Serialize + ?Sized;
    fn get_confirmed<Q>(&'a self, key: &Q) -> Result<Option<Cow<'a, V>>>
       where K: Borrow<Q>,
             Q: PartialEq + Eq + Hash + Serialize + ?Sized;
    fn get_pending<Q>(&self, key: &Q) -> Option<Option<V>>
       where K: Borrow<Q>,
             Q: PartialEq + Eq + Hash + Serialize + ?Sized;
    fn iter_pending(&'a self) -> Self::PendingIterator;
    fn iter_confirmed(&'a self) -> Self::Iterator;
    fn keys_confirmed(&'a self) -> Self::Keys;
    fn values_confirmed(&'a self) -> Self::Values;

    // Provided methods
    fn is_empty_confirmed(&self) -> bool { ... }
    fn get_speculative<Q>(&'a self, key: &Q) -> Result<Option<Cow<'a, V>>>
       where K: Borrow<Q>,
             Q: PartialEq + Eq + Hash + Serialize + ?Sized { ... }
}
Expand description

A trait representing map-like storage operations with read-only capabilities.

Required Associated Types§

Source

type PendingIterator: Iterator<Item = (Cow<'a, K>, Option<Cow<'a, V>>)>

Source

type Iterator: Iterator<Item = (Cow<'a, K>, Cow<'a, V>)>

Source

type Keys: Iterator<Item = Cow<'a, K>>

Source

type Values: Iterator<Item = Cow<'a, V>>

Required Methods§

Source

fn len_confirmed(&self) -> usize

Returns the number of confirmed entries in the map.

Source

fn contains_key_confirmed<Q>(&self, key: &Q) -> Result<bool>
where K: Borrow<Q>, Q: PartialEq + Eq + Hash + Serialize + ?Sized,

Returns true if the given key exists in the map.

Source

fn contains_key_speculative<Q>(&self, key: &Q) -> Result<bool>
where K: Borrow<Q>, Q: PartialEq + Eq + Hash + Serialize + ?Sized,

Returns true if the given key exists in the map. This method first checks the atomic batch, and if it does not exist, then checks the map.

Source

fn get_confirmed<Q>(&'a self, key: &Q) -> Result<Option<Cow<'a, V>>>
where K: Borrow<Q>, Q: PartialEq + Eq + Hash + Serialize + ?Sized,

Returns the value for the given key from the map, if it exists.

Source

fn get_pending<Q>(&self, key: &Q) -> Option<Option<V>>
where K: Borrow<Q>, Q: PartialEq + Eq + Hash + Serialize + ?Sized,

Returns the current value for the given key if it is scheduled to be inserted as part of an atomic batch.

If the key does not exist, returns None. If the key is removed in the batch, returns Some(None). If the key is inserted in the batch, returns Some(Some(value)).

Source

fn iter_pending(&'a self) -> Self::PendingIterator

Returns an iterator visiting each key-value pair in the atomic batch.

Source

fn iter_confirmed(&'a self) -> Self::Iterator

Returns an iterator visiting each key-value pair in the map.

Source

fn keys_confirmed(&'a self) -> Self::Keys

Returns an iterator over each key in the map.

Source

fn values_confirmed(&'a self) -> Self::Values

Returns an iterator over each value in the map.

Provided Methods§

Source

fn is_empty_confirmed(&self) -> bool

Checks whether there are any confirmed entries in the map.

Source

fn get_speculative<Q>(&'a self, key: &Q) -> Result<Option<Cow<'a, V>>>
where K: Borrow<Q>, Q: PartialEq + Eq + Hash + Serialize + ?Sized,

Returns the value for the given key from the atomic batch first, if it exists, or return from the map, otherwise.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<'a, K: 'a + Copy + Clone + PartialEq + Eq + Hash + Serialize + for<'de> Deserialize<'de> + Send + Sync, V: 'a + Clone + PartialEq + Eq + Serialize + for<'de> Deserialize<'de> + Send + Sync> MapRead<'a, K, V> for MemoryMap<K, V>

Source§

type Iterator = Map<IntoIter<Vec<u8>, V>, fn(_: (Vec<u8>, V)) -> (Cow<'a, K>, Cow<'a, V>)>

Source§

type Keys = Map<IntoKeys<Vec<u8>, V>, fn(_: Vec<u8>) -> Cow<'a, K>>

Source§

type PendingIterator = Map<IntoIter<K, Option<V>>, fn(_: (K, Option<V>)) -> (Cow<'a, K>, Option<Cow<'a, V>>)>

Source§

type Values = Map<IntoValues<Vec<u8>, V>, fn(_: V) -> Cow<'a, V>>