pub struct Infinitree<I, CustomData = ()>{ /* 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>
impl<I: Index + Default, CustomData> Infinitree<I, CustomData>
Sourcepub fn empty(
backend: Arc<dyn Backend>,
key: impl Into<Key>,
) -> Result<Infinitree<I, CustomData>>
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§impl<I: Index, CustomData> Infinitree<I, CustomData>
impl<I: Index, CustomData> Infinitree<I, CustomData>
Sourcepub fn commit(
&self,
message: impl Into<Message>,
) -> Result<Option<Arc<Commit<CustomData>>>>
pub fn commit( &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>
impl<I: Index, CustomData> Infinitree<I, CustomData>
Sourcepub fn with_key(
backend: Arc<dyn Backend>,
index: I,
key: impl Into<Key>,
) -> Result<Infinitree<I, CustomData>>
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.
Sourcepub fn reseal(&self) -> Result<()>
pub fn reseal(&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.
Sourcepub fn commit_list(&self) -> impl Deref<Target = CommitList<CustomData>> + '_
pub fn commit_list(&self) -> impl Deref<Target = CommitList<CustomData>> + '_
Return all generations in the tree.
Sourcepub fn filter_commits(&self, version: CommitFilter)
pub fn filter_commits(&self, version: CommitFilter)
Sourcepub fn commit_with_custom_data(
&self,
message: impl Into<Message>,
mode: CommitMode,
custom_data: CustomData,
) -> Result<Option<Arc<Commit<CustomData>>>>
pub fn commit_with_custom_data( &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
.
Sourcepub fn commit_with_metadata(
&self,
metadata: CommitMetadata<CustomData>,
mode: CommitMode,
) -> Result<Option<Arc<Commit<CustomData>>>>
pub fn commit_with_metadata( &self, metadata: CommitMetadata<CustomData>, mode: CommitMode, ) -> Result<Option<Arc<Commit<CustomData>>>>
Commit using manually prepared metadata
For full documentation, please read Infinitree::commit
.
Sourcepub fn storage_writer(&self) -> Result<AEADWriter>
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.
Sourcepub fn storage_reader(&self) -> Result<PoolRef<AEADReader>>
pub fn storage_reader(&self) -> Result<PoolRef<AEADReader>>
Return a handle for an object reader
The object reader is for reading out those ChunkPointer
s
that you get when using an AEADWriter
stack manually.
You can obtain an AEADWriter
using object_writer
.
Source§impl<I: Index, CustomData> Infinitree<I, CustomData>
impl<I: Index, CustomData> Infinitree<I, CustomData>
Sourcepub fn load_all(&self) -> Result<()>
pub fn load_all(&self) -> Result<()>
Load into memory all fields for the selected version ranges
Sourcepub fn load(&self, field: impl Into<Intent<Box<dyn Load>>>) -> Result<()>
pub fn load(&self, field: impl Into<Intent<Box<dyn Load>>>) -> Result<()>
Load the field for the selected generation set
Sourcepub fn query<K>(
&self,
field: Intent<Box<impl Query<Key = K>>>,
pred: impl Fn(&K) -> QueryAction,
) -> Result<()>
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
Sourcepub 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,
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
Sourcepub fn index(&self) -> impl Deref<Target = I> + '_
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.
Sourcepub fn backend(&self) -> Arc<dyn Backend>
pub fn backend(&self) -> Arc<dyn Backend>
Return the backend
This allows synchronization of backends that queue upload jobs, or other background tasks.
Sourcepub fn index_object_count(&self) -> usize
pub fn index_object_count(&self) -> usize
Returns the number of index objects
Source§impl<I, CustomData> Infinitree<I, CustomData>
impl<I, CustomData> Infinitree<I, CustomData>
Sourcepub fn root_intent(&self) -> Intent<Box<LocalField<I>>>
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
].