Struct typed_sled::Tree[][src]

pub struct Tree<K, V> { /* fields omitted */ }
Expand description

A flash-sympathetic persistent lock-free B+ tree.

A Tree represents a single logical keyspacFe / namespace / bucket.

Example


let db: sled::Db = sled::open("db")?;
let animals = typed_sled::Tree::<String, Animal>::open(&db, "animals");
animals.insert(&"Larry".to_string(), &Animal::Dog);

Implementations

Initialize a typed tree. The id identifies the tree to be opened from the db.

Example

let db: sled::Db = sled::open("db")?;
let animals = typed_sled::Tree::<String, Animal>::open(&db, "animals");
animals.insert(&"Larry".to_string(), &Animal::Dog)?;

Insert a key to a new value, returning the last value if it was set.

Perform a multi-key serializable transaction.

Create a new batched update that can be atomically applied.

It is possible to apply a Batch in a transaction as well, which is the way you can apply a Batch to multiple Trees atomically.

Retrieve a value from the Tree if it exists.

Delete a value, returning the old value if it existed.

Compare and swap. Capable of unique creation, conditional modification, or deletion. If old is None, this will only set the value if it doesn’t exist yet. If new is None, will delete the value if old is correct. If both old and new are Some, will modify the value if old is correct.

It returns Ok(Ok(())) if operation finishes successfully.

If it fails it returns: - Ok(Err(CompareAndSwapError(current, proposed))) if operation failed to setup a new value. CompareAndSwapError contains current and proposed values. - Err(Error::Unsupported) if the database is opened in read-only mode.

Fetch the value, apply a function to it and return the result.

Fetch the value, apply a function to it and return the previous value.

Subscribe to Events that happen to keys that have the specified prefix. Events for particular keys are guaranteed to be witnessed in the same order by all threads, but threads may witness different interleavings of Events across different keys. If subscribers don’t keep up with new writes, they will cause new writes to block. There is a buffer of 1024 items per Subscriber. This can be used to build reactive and replicated systems.

Synchronously flushes all dirty IO buffers and calls fsync. If this succeeds, it is guaranteed that all previous writes will be recovered if the system crashes. Returns the number of bytes flushed during this call.

Flushing can take quite a lot of time, and you should measure the performance impact of using it on realistic sustained workloads running on realistic hardware.

Asynchronously flushes all dirty IO buffers and calls fsync. If this succeeds, it is guaranteed that all previous writes will be recovered if the system crashes. Returns the number of bytes flushed during this call.

Flushing can take quite a lot of time, and you should measure the performance impact of using it on realistic sustained workloads running on realistic hardware.

Returns true if the Tree contains a value for the specified key.

Retrieve the key and value before the provided key, if one exists.

Retrieve the next key and value from the Tree after the provided key.

Merge state directly into a given key’s value using the configured merge operator. This allows state to be written into a value directly, without any read-modify-write steps. Merge operators can be used to implement arbitrary data structures.

Calling merge will return an Unsupported error if it is called without first setting a merge operator function.

Merge operators are shared by all instances of a particular Tree. Different merge operators may be set on different Trees.

Sets a merge operator for use with the merge function.

Merge state directly into a given key’s value using the configured merge operator. This allows state to be written into a value directly, without any read-modify-write steps. Merge operators can be used to implement arbitrary data structures.

Panics

Calling merge will panic if no merge operator has been configured.

Create a double-ended iterator over the tuples of keys and values in this tree.

Create a double-ended iterator over tuples of keys and values, where the keys fall within the specified range.

Create an iterator over tuples of keys and values, where the all the keys starts with the given prefix.

Returns the first key and value in the Tree, or None if the Tree is empty.

Returns the last key and value in the Tree, or None if the Tree is empty.

Atomically removes the maximum item in the Tree instance.

Atomically removes the minimum item in the Tree instance.

Returns the number of elements in this tree.

Returns true if the Tree contains no elements.

Clears the Tree, removing all values.

Note that this is not atomic.

Returns the name of the tree.

Returns the CRC32 of all keys and values in this Tree.

This is O(N) and locks the underlying tree for the duration of the entire scan.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The alignment of pointer.

The type for initializers.

Initializes a with the given initializer. Read more

Dereferences the given pointer. Read more

Mutably dereferences the given pointer. Read more

Drops the object pointed to by the given pointer. Read more

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.