Struct infinitree::tree::Infinitree

source ·
pub struct Infinitree<I, CustomData = ()>where
    CustomData: Serialize + DeserializeOwned + Send + Sync + 'static,{ /* private fields */ }
Expand description

An Infinitree root.

This is primarily a wrapper around an Index that manages versioning and key management.

Implementations§

source§

impl<I: Index + Default, CustomData> Infinitree<I, CustomData>where CustomData: Serialize + DeserializeOwned + Send + Sync,

source

pub fn empty( backend: Arc<dyn Backend>, key: impl Into<Key> ) -> Result<Infinitree<I, CustomData>>

Initialize an empty index and tree with no version history.

Examples
use infinitree::{*, crypto::UsernamePassword, fields::Serialized, backends::Directory};

#[derive(Index, Default)]
struct Measurements {
    list: Serialized<Vec<usize>>
}

let mut tree = Infinitree::<Measurements>::empty(
    Directory::new("/storage").unwrap(),
    UsernamePassword::with_credentials("username".to_string(),
                                       "password".to_string()).unwrap()
).unwrap();
source

pub fn open( backend: Arc<dyn Backend>, key: impl Into<Key> ) -> Result<Infinitree<I, CustomData>>

Load all version information from the tree.

This method doesn’t load the index, only the associated metadata.

source§

impl<I: Index, CustomData> Infinitree<I, CustomData>where CustomData: Serialize + DeserializeOwned + Send + Sync + Default,

source

pub fn commit( &mut self, message: impl Into<Message> ) -> Result<Option<Arc<Commit<CustomData>>>>

Create a commit if there are changes in the index.

This persists currently in-memory data, and also records the commit with message to the log.

Examples

Any commit message works that implements ToString.

use infinitree::{*, crypto::UsernamePassword, fields::Serialized, backends::Directory};

let mut tree = Infinitree::<infinitree::fields::VersionedMap<String, String>>::empty(
    Directory::new("/storage").unwrap(),
    UsernamePassword::with_credentials("username".to_string(), "password".to_string()).unwrap()
).unwrap();

// Commit message can be omitted using `None`
tree.commit(None);

// Otherwise a hardcoded &str also works
tree.commit("this is a message");

// Or even a String instance
let message = "this is a string".to_string();
tree.commit(message);
source§

impl<I: Index, CustomData> Infinitree<I, CustomData>where CustomData: Serialize + DeserializeOwned + Send + Sync,

source

pub fn with_key( backend: Arc<dyn Backend>, index: I, key: impl Into<Key> ) -> Result<Infinitree<I, CustomData>>

Wraps the given index in an Infinitree.

This is primarily useful if you’re done writing an Index, and want to commit and persist it, or if you need extra initialization because Default is not viable.

source

pub fn reseal(&mut self) -> Result<()>

Change the current wrapping key and immediately commit to the backend.

Will return an error if the operation is not supported by either the new or the old key.

source

pub fn commit_list(&self) -> impl Deref<Target = CommitList<CustomData>> + '_

Return all generations in the tree.

source

pub fn filter_commits(&mut self, version: CommitFilter)

Only run persistence query operations (query, load, iter) on the selected generations.

source

pub fn commit_with_custom_data( &mut self, message: impl Into<Message>, mode: CommitMode, custom_data: CustomData ) -> Result<Option<Arc<Commit<CustomData>>>>

Commit changes currently in the index.

For full documentation, please read Infinitree::commit.

source

pub fn commit_with_metadata( &mut self, metadata: CommitMetadata<CustomData>, mode: CommitMode ) -> Result<Option<Arc<Commit<CustomData>>>>

Commit using manually prepared metadata

For full documentation, please read Infinitree::commit.

source

pub fn storage_writer(&self) -> Result<AEADWriter>

Return a handle for an object writer.

This can be used to manually write sparse data if you don’t want to store it in memory. Especially useful for e.g. files.

Note that currently there’s no fragmenting internally, so anything written using an ObjectWriter must be less than about 4MB.

source

pub fn storage_reader(&self) -> Result<PoolRef<AEADReader>>

Return a handle for an object reader

The object reader is for reading out those ChunkPointers that you get when using an AEADWriter stack manually.

You can obtain an AEADWriter using object_writer.

source

pub fn hasher(&self) -> Result<Hasher>

Get a hasher that produces hashes only usable with this stash’s keys

This internally is a keyed Blake3 instance.

source§

impl<I: Index, CustomData> Infinitree<I, CustomData>where CustomData: Serialize + DeserializeOwned + Send + Sync,

source

pub fn load_all(&self) -> Result<()>

Load into memory all fields for the selected version ranges

source

pub fn load(&self, field: impl Into<Intent<Box<dyn Load>>>) -> Result<()>

Load the field for the selected generation set

source

pub fn query<K>( &self, field: Intent<Box<impl Query<Key = K>>>, pred: impl Fn(&K) -> QueryAction ) -> Result<()>

Load into memory all data from field where pred returns true

source

pub fn iter<'a, K, O, Q>( &'a self, field: Intent<Box<Q>>, pred: impl Fn(&K) -> QueryAction + Send + Sync + 'static ) -> Result<impl Iterator<Item = O> + Send + Sync + '_>where for<'de> Q::Serialized: Deserialize<'de>, Q: Collection<Key = K, Item = O> + Send + Sync + 'static, K: Eq + Hash + Clone + Send + Sync + 'a,

Same as query, but returns an Iterator

source

pub fn index(&self) -> impl Deref<Target = I> + '_

Return an immutable reference to the internal index.

By design this is read-only, as the index fields should use internal mutability and be thread-safe individually.

source

pub fn backend(&self) -> Arc<dyn Backend>

Return the backend

This allows synchronization of backends that queue upload jobs, or other background tasks.

source

pub fn index_object_count(&self) -> usize

Returns the number of index objects

source§

impl<I, CustomData> Infinitree<I, CustomData>where CustomData: Serialize + DeserializeOwned + Send + Sync, I: Index + Clone + Store,

source

pub fn root_intent(&self) -> Intent<Box<LocalField<I>>>

If the Index of the tree is a primitive field, retrieve a handle.

This is mostly useful when used in conjunction with [Tree::iter].

Trait Implementations§

source§

impl<I, CustomData> Drop for Infinitree<I, CustomData>where CustomData: Serialize + DeserializeOwned + Send + Sync + 'static,

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<I, CustomData = ()> !RefUnwindSafe for Infinitree<I, CustomData>

§

impl<I, CustomData> Send for Infinitree<I, CustomData>where I: Send,

§

impl<I, CustomData> Sync for Infinitree<I, CustomData>where I: Send + Sync,

§

impl<I, CustomData> Unpin for Infinitree<I, CustomData>where I: Unpin,

§

impl<I, CustomData = ()> !UnwindSafe for Infinitree<I, CustomData>

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

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

§

fn vzip(self) -> V