Skip to main content

Store

Trait Store 

Source
pub trait Store:
    Clone
    + Debug
    + Default
    + Send
    + Sync {
    // Required methods
    fn get(&self, key: &str) -> Option<&Arc<Entry>>;
    fn insert(&self, key: String, value: Arc<Entry>) -> Self;
    fn remove(&self, key: &str) -> Self;
    fn insert_mut(&mut self, key: String, value: Arc<Entry>);
    fn remove_mut(&mut self, key: &str) -> bool;
    fn len(&self) -> usize;
    fn iter(&self) -> impl Iterator<Item = (&String, &Arc<Entry>)>;
    fn range_prefix<'a>(
        &'a self,
        prefix: &'a str,
    ) -> impl Iterator<Item = (&'a String, &'a Arc<Entry>)>;
    fn shares_allocation_with(&self, other: &Self) -> bool;

    // Provided method
    fn is_empty(&self) -> bool { ... }
}
Expand description

A persistent ordered map from key to entry.

Implementations must iterate in ascending key order, because that ordering is what makes commit ids and listings reproducible.

Required Methods§

Source

fn get(&self, key: &str) -> Option<&Arc<Entry>>

Look a key up.

Source

fn insert(&self, key: String, value: Arc<Entry>) -> Self

Return a new map with key set, leaving self untouched.

Source

fn remove(&self, key: &str) -> Self

Return a new map with key removed, leaving self untouched.

Source

fn insert_mut(&mut self, key: String, value: Arc<Entry>)

Set key in place. Equivalent to *self = self.insert(..), but skips copying nodes this map holds exclusively.

Source

fn remove_mut(&mut self, key: &str) -> bool

Remove key in place. Returns whether the key was present.

Source

fn len(&self) -> usize

Number of entries.

Source

fn iter(&self) -> impl Iterator<Item = (&String, &Arc<Entry>)>

All entries, in ascending key order.

Source

fn range_prefix<'a>( &'a self, prefix: &'a str, ) -> impl Iterator<Item = (&'a String, &'a Arc<Entry>)>

All entries whose key starts with prefix, in ascending key order.

Source

fn shares_allocation_with(&self, other: &Self) -> bool

Whether two maps are the same allocation, i.e. share all their nodes.

Used by the test that shows forking copies nothing.

Provided Methods§

Source

fn is_empty(&self) -> bool

Whether the map is empty.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§