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
sourceimpl<I: Index + Default, CustomData> Infinitree<I, CustomData> where
CustomData: Serialize + DeserializeOwned + Send + Sync,
impl<I: Index + Default, CustomData> Infinitree<I, CustomData> where
CustomData: Serialize + DeserializeOwned + Send + Sync,
sourcepub fn empty(backend: Arc<dyn Backend>, master_key: Key) -> Self
pub fn empty(backend: Arc<dyn Backend>, master_key: Key) -> Self
Initialize an empty index and tree with no version history.
Examples
use infinitree::{Infinitree, Key, fields::Serialized, backends::Directory};
#[derive(infinitree::Index, Default)]
struct Measurements {
list: Serialized<Vec<usize>>
}
let mut tree = Infinitree::<Measurements>::empty(
Directory::new("/storage").unwrap(),
Key::from_credentials("username", "password").unwrap()
);
sourceimpl<I: Index, CustomData> Infinitree<I, CustomData> where
CustomData: Serialize + DeserializeOwned + Send + Sync + Default,
impl<I: Index, CustomData> Infinitree<I, CustomData> where
CustomData: Serialize + DeserializeOwned + Send + Sync + Default,
sourcepub fn commit(&mut self, message: impl Into<Message>) -> Result<()>
pub fn commit(&mut self, message: impl Into<Message>) -> Result<()>
Commit changes currently 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::{Infinitree, Key, fields::Serialized, backends::Directory};
let mut tree = Infinitree::<infinitree::fields::VersionedMap<String, String>>::empty(
Directory::new("/storage").unwrap(),
Key::from_credentials("username", "password").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);
sourceimpl<I: Index, CustomData> Infinitree<I, CustomData> where
CustomData: Serialize + DeserializeOwned + Send + Sync,
impl<I: Index, CustomData> Infinitree<I, CustomData> where
CustomData: Serialize + DeserializeOwned + Send + Sync,
sourcepub fn with_key(backend: Arc<dyn Backend>, index: I, master_key: Key) -> Self
pub fn with_key(backend: Arc<dyn Backend>, index: I, master_key: Key) -> Self
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 commit_list(&self) -> impl Deref<Target = Vec<Commit<CustomData>>> + '_
pub fn commit_list(&self) -> impl Deref<Target = Vec<Commit<CustomData>>> + '_
Return all generations in the tree.
sourcepub fn filter_commits(&mut self, version: CommitFilter)
pub fn filter_commits(&mut self, version: CommitFilter)
sourcepub fn commit_with_custom_data(
&mut self,
message: impl Into<Message>,
custom_data: CustomData
) -> Result<()>
pub fn commit_with_custom_data(
&mut self,
message: impl Into<Message>,
custom_data: CustomData
) -> Result<()>
Commit changes currently in the index.
For full documentation, please read Infinitree::commit
.
sourcepub fn commit_with_metadata(
&mut self,
metadata: CommitMetadata<CustomData>
) -> Result<()>
pub fn commit_with_metadata(
&mut self,
metadata: CommitMetadata<CustomData>
) -> Result<()>
Commit using manually prepared metadata
For full documentation, please read Infinitree::commit
.
sourcepub fn load_all(&mut self) -> Result<()>
pub fn load_all(&mut 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<K, O, Q>(
&self,
field: Intent<Box<Q>>,
pred: impl Fn(&K) -> QueryAction + 'static
) -> Result<impl Iterator<Item = O> + '_> where
for<'de> <Q as Collection>::Serialized: Deserialize<'de>,
Q: Collection<Key = K, Item = O> + 'static,
pub fn iter<K, O, Q>(
&self,
field: Intent<Box<Q>>,
pred: impl Fn(&K) -> QueryAction + 'static
) -> Result<impl Iterator<Item = O> + '_> where
for<'de> <Q as Collection>::Serialized: Deserialize<'de>,
Q: Collection<Key = K, Item = O> + 'static,
Same as query
, but returns an Iterator
sourcepub fn object_writer(&self) -> Result<AEADWriter>
pub fn object_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 object_reader(&self) -> Result<AEADReader>
pub fn object_reader(&self) -> Result<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
.
Trait Implementations
sourceimpl<I, CustomData> Drop for Infinitree<I, CustomData> where
CustomData: Serialize + DeserializeOwned + Send + Sync + 'static,
impl<I, CustomData> Drop for Infinitree<I, CustomData> where
CustomData: Serialize + DeserializeOwned + Send + Sync + 'static,
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
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more