Trait DbExt

Source
pub trait DbExt {
    // Required methods
    fn open_expiring_tree<V, E, F>(&self, name: &str) -> TreeBuilder<V, E, F>
       where E: Encoding<HashSet<IVec>> + Encoding<DateTime<Utc>> + 'static,
             F: Encoding<V> + 'static;
    fn open_structured_tree<V, E>(&self, name: &str) -> Result<Tree<V, E>>
       where E: Encoding<V> + 'static;

    // Provided methods
    fn open_expiring_structured_tree<V, E>(
        &self,
        name: &str,
    ) -> TreeBuilder<V, E>
       where E: Encoding<V> + Encoding<HashSet<IVec>> + Encoding<DateTime<Utc>> + 'static,
             V: DeserializeOwned + Serialize + 'static { ... }
    fn open_expiring_plain_tree<E>(&self, name: &str) -> TreeBuilder<E>
       where E: Encoding<HashSet<IVec>> + Encoding<DateTime<Utc>> + 'static { ... }
}
Expand description

Extensions for the sled Db type that provides different ways of opening trees for storing structured data.

Example:

use sled_extensions::{Config, DbExt};

let db = Config::default().temporary(true).open()?;
let tree = db.open_json_tree::<()>("json-tree")?;

Required Methods§

Source

fn open_expiring_tree<V, E, F>(&self, name: &str) -> TreeBuilder<V, E, F>
where E: Encoding<HashSet<IVec>> + Encoding<DateTime<Utc>> + 'static, F: Encoding<V> + 'static,

Open an expiring tree

Expiring trees are trees that keep track of insert and update times in order to help cache implementations. While this library on it’s own doesn’t provide a fully-featured cache, implementing a cache on top of an expiring tree is simple.

This tree can have numerous types, for example,

use sled_extensions::{Config, DbExt, bincode, cbor, json};
let tree: bincode::expiring::Tree<()> = db.open_expiring_tree("bincode-tree").build()?;
let tree: cbor::expiring::Tree<()> = db.open_expiring_tree("cbor-tree").build()?;
let tree: json::expiring::Tree<()> = db.open_expiring_tree("json-tree").build()?;

While it is possible to use only this method to open many kinds of expiring trees, it may be easier to use a more specific tree opening method.

Source

fn open_structured_tree<V, E>(&self, name: &str) -> Result<Tree<V, E>>
where E: Encoding<V> + 'static,

Open a structured tree

Structured trees are a thin wrapper on top of basic sled trees that provides encoding and decoding for the data stored in the tree.

This tree can have numerous types, for example,

use sled_extensions::{Config, DbExt, bincode, cbor, json};
let tree: bincode::Tree<()> = db.open_structured_tree("bincode-tree")?;
let tree: cbor::Tree<()> = db.open_structured_tree("cbor-tree")?;
let tree: json::Tree<()> = db.open_structured_tree("json-tree")?;

While it is possible to use only this method to open many kinds of structured trees, it may be easier to use a more specific tree opening method.

Provided Methods§

Source

fn open_expiring_structured_tree<V, E>(&self, name: &str) -> TreeBuilder<V, E>
where E: Encoding<V> + Encoding<HashSet<IVec>> + Encoding<DateTime<Utc>> + 'static, V: DeserializeOwned + Serialize + 'static,

Open an expiring tree using an encoding for both metadata storage and value storage

Source

fn open_expiring_plain_tree<E>(&self, name: &str) -> TreeBuilder<E>
where E: Encoding<HashSet<IVec>> + Encoding<DateTime<Utc>> + 'static,

Open an expiring tree using an encoding for metadata storage

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 DbExt for Db