pub struct EntryBuilder { /* private fields */ }Expand description
A builder for creating Entry instances.
EntryBuilder allows mutable construction of an entry’s content.
Once finalized with the build() method, it produces an immutable Entry
with a deterministically calculated ID.
§Parameter Type Efficiency
The builder uses impl Into<ID> and impl Into<RawData> for parameters, allowing you to pass
string literals, &str, String, or the appropriate types without unnecessary conversions:
// Efficient - no unnecessary .to_string() calls needed
let entry = Entry::builder("root_id")
.add_parent("parent1")
.set_subtree_data("users", "user_data")
.build();§Mutable Construction
The builder provides two patterns for construction:
-
Ownership chaining: Each method returns
selffor chained calls.let entry = Entry::builder(root_id) .set_subtree_data("users".to_string(), "user_data".to_string()) .add_parent("parent_id".to_string()) .build(); -
Mutable reference: Methods ending in
_mutmodify the builder in place.let mut builder = Entry::builder(root_id); builder.set_subtree_data_mut("users".to_string(), "user_data".to_string()); builder.add_parent_mut("parent_id".to_string()); let entry = builder.build();
§Example
use eidetica::Entry;
// Create a builder for a regular entry
let entry = Entry::builder("root_id")
.add_parent("parent1")
.set_subtree_data("users", "user_data")
.build();
// Create a builder for a top-level root entry
let root_entry = Entry::root_builder()
.set_subtree_data("users", "initial_user_data")
.build();Implementations§
Source§impl EntryBuilder
impl EntryBuilder
Sourcepub fn new(root: impl Into<ID>) -> Self
pub fn new(root: impl Into<ID>) -> Self
Creates a new EntryBuilder for an entry associated with a specific tree root.
§Arguments
root- TheIDof the rootEntryof the tree this entry will belong to.
Note: It’s generally preferred to use the static Entry::builder() method
instead of calling this constructor directly.
Sourcepub fn new_top_level() -> Self
pub fn new_top_level() -> Self
Creates a new EntryBuilder for a top-level (root) entry for a new tree.
Root entries have an empty string as their root ID and include a special ROOT subtree marker.
This method is typically used when creating a new tree.
Note: It’s generally preferred to use the static Entry::root_builder() method
instead of calling this constructor directly.
Sourcepub fn set_sig(self, sig: SigInfo) -> Self
pub fn set_sig(self, sig: SigInfo) -> Self
Set the authentication information for this entry.
§Arguments
auth- The authentication information including key ID and optional signature
Sourcepub fn set_sig_mut(&mut self, sig: SigInfo) -> &mut Self
pub fn set_sig_mut(&mut self, sig: SigInfo) -> &mut Self
Mutable reference version of set_auth. Set the authentication information for this entry.
§Arguments
auth- The authentication information including key ID and optional signature
Sourcepub fn subtrees(&self) -> Vec<String>
pub fn subtrees(&self) -> Vec<String>
Get the names of all subtrees this entry builder contains data for. The names are returned in alphabetical order.
Sourcepub fn data(&self, subtree_name: impl AsRef<str>) -> Result<&RawData>
pub fn data(&self, subtree_name: impl AsRef<str>) -> Result<&RawData>
Get the RawData for a specific named subtree within this entry builder.
Returns an error if the subtree is not found or if the subtree exists but has no data (None).
Sourcepub fn parents(&self) -> Result<Vec<ID>>
pub fn parents(&self) -> Result<Vec<ID>>
Get the IDs of the parent entries for the main tree. The parent IDs are returned in alphabetical order.
Sourcepub fn subtree_parents(&self, subtree_name: impl AsRef<str>) -> Result<Vec<ID>>
pub fn subtree_parents(&self, subtree_name: impl AsRef<str>) -> Result<Vec<ID>>
Get the IDs of the parent entries specific to a named subtree’s history. The parent IDs are returned in alphabetical order.
Sourcepub fn set_subtree_data(
self,
name: impl Into<String>,
data: impl Into<RawData>,
) -> Self
pub fn set_subtree_data( self, name: impl Into<String>, data: impl Into<RawData>, ) -> Self
Sets data for a named subtree, creating it if it doesn’t exist.
The list of subtrees will be sorted by name when build() is called.
§Arguments
name- The name of the subtree (e.g., “users”, “products”).data-RawData(serialized string) specific to this entry for the named subtree.
Sourcepub fn set_subtree_data_mut(
&mut self,
name: impl Into<String>,
data: impl Into<RawData>,
) -> &mut Self
pub fn set_subtree_data_mut( &mut self, name: impl Into<String>, data: impl Into<RawData>, ) -> &mut Self
Mutable reference version of set_subtree_data.
Sets data for a named subtree, creating it if it doesn’t exist.
The list of subtrees will be sorted by name when build() is called.
§Arguments
name- The name of the subtree (e.g., “users”, “products”).data-RawData(serialized string) specific to this entry for the named subtree.
Sourcepub fn remove_empty_subtrees(self) -> Result<Self>
pub fn remove_empty_subtrees(self) -> Result<Self>
Removes subtrees that have empty data.
This removes subtrees with Some("") (actual empty data) and subtrees with None
(no data changes) UNLESS the subtree is referenced in the _index subtree’s data.
When _index is updated for a subtree, that subtree must appear in the Entry.
This is marked by having None data and being referenced in _index.
This is useful for cleaning up entries before building.
§Errors
Returns an error if the _index subtree data exists but cannot be deserialized.
Sourcepub fn remove_empty_subtrees_mut(&mut self) -> Result<&mut Self>
pub fn remove_empty_subtrees_mut(&mut self) -> Result<&mut Self>
Mutable reference version of remove_empty_subtrees.
Removes subtrees with Some("") and subtrees with None unless referenced in _index.
§Errors
Returns an error if the _index subtree data exists but cannot be deserialized.
Sourcepub fn set_root_mut(&mut self, root: impl Into<String>) -> &mut Self
pub fn set_root_mut(&mut self, root: impl Into<String>) -> &mut Self
Sourcepub fn set_parents(self, parents: Vec<ID>) -> Self
pub fn set_parents(self, parents: Vec<ID>) -> Self
Set the parent IDs for the main tree history.
The provided vector will be sorted alphabetically during the build() process.
Sourcepub fn set_parents_mut(&mut self, parents: Vec<ID>) -> &mut Self
pub fn set_parents_mut(&mut self, parents: Vec<ID>) -> &mut Self
Mutable reference version of set_parents.
Set the parent IDs for the main tree history.
The provided vector will be sorted alphabetically during the build() process.
Sourcepub fn add_parent(self, parent_id: impl Into<String>) -> Self
pub fn add_parent(self, parent_id: impl Into<String>) -> Self
Add a single parent ID to the main tree history.
Parents will be sorted and duplicates handled during the build() process.
Sourcepub fn add_parent_mut(&mut self, parent_id: impl Into<String>) -> &mut Self
pub fn add_parent_mut(&mut self, parent_id: impl Into<String>) -> &mut Self
Mutable reference version of add_parent.
Add a single parent ID to the main tree history.
Parents will be sorted and duplicates handled during the build() process.
Sourcepub fn get_parents(&self) -> Option<&Vec<ID>>
pub fn get_parents(&self) -> Option<&Vec<ID>>
Get a reference to the current parent IDs for the main tree history.
Sourcepub fn set_subtree_parents(
self,
subtree_name: impl Into<String>,
parents: Vec<ID>,
) -> Self
pub fn set_subtree_parents( self, subtree_name: impl Into<String>, parents: Vec<ID>, ) -> Self
Set the parent IDs for a specific named subtree’s history.
The provided vector will be sorted alphabetically and de-duplicated during the build() process.
If the subtree does not exist, it will be created with empty data (“{}”).
The list of subtrees will be sorted by name when build() is called.
Sourcepub fn set_subtree_parents_mut(
&mut self,
subtree_name: impl Into<String>,
parents: Vec<ID>,
) -> &mut Self
pub fn set_subtree_parents_mut( &mut self, subtree_name: impl Into<String>, parents: Vec<ID>, ) -> &mut Self
Mutable reference version of set_subtree_parents.
Set the parent IDs for a specific named subtree’s history.
The provided vector will be sorted alphabetically and de-duplicated during the build() process.
If the subtree does not exist, it will be created with no data (None).
The list of subtrees will be sorted by name when build() is called.
Sourcepub fn add_subtree_parent(
self,
subtree_name: impl Into<String>,
parent_id: impl Into<String>,
) -> Self
pub fn add_subtree_parent( self, subtree_name: impl Into<String>, parent_id: impl Into<String>, ) -> Self
Add a single parent ID to a specific named subtree’s history.
If the subtree does not exist, it will be created with no data (None).
Parent IDs will be sorted and de-duplicated during the build() process.
The list of subtrees will be sorted by name when build() is called.
Sourcepub fn add_subtree_parent_mut(
&mut self,
subtree_name: impl Into<String>,
parent_id: impl Into<String>,
) -> &mut Self
pub fn add_subtree_parent_mut( &mut self, subtree_name: impl Into<String>, parent_id: impl Into<String>, ) -> &mut Self
Mutable reference version of add_subtree_parent.
Add a single parent ID to a specific named subtree’s history.
If the subtree does not exist, it will be created with no data (None).
Parent IDs will be sorted and de-duplicated during the build() process.
The list of subtrees will be sorted by name when build() is called.
Sourcepub fn set_metadata(self, metadata: impl Into<String>) -> Self
pub fn set_metadata(self, metadata: impl Into<String>) -> Self
Set the metadata for this entry’s tree node.
Metadata is optional information attached to an entry that is not part of the main data model and is not merged between entries. It’s used primarily for improving efficiency of operations and for experimentation.
For example, metadata can contain references to the current tips of the settings subtree, allowing for efficient verification in sparse checkout scenarios.
§Arguments
metadata-RawData(serialized string) for the main tree node metadata.
§Returns
Self for method chaining.
Sourcepub fn set_metadata_mut(&mut self, metadata: impl Into<String>) -> &mut Self
pub fn set_metadata_mut(&mut self, metadata: impl Into<String>) -> &mut Self
Mutable reference version of set_metadata. Set the metadata for this entry’s tree node.
Metadata is optional information attached to an entry that is not part of the main data model and is not merged between entries. It’s used primarily for improving efficiency of operations and for experimentation.
For example, metadata can contain references to the current tips of the settings subtree, allowing for efficient verification in sparse checkout scenarios.
§Arguments
metadata-RawData(serialized string) for the main tree node metadata.
§Returns
A mutable reference to self for method chaining.
Sourcepub fn metadata(&self) -> Option<&RawData>
pub fn metadata(&self) -> Option<&RawData>
Get the current metadata value for this entry builder.
Metadata is optional information attached to an entry that is not part of the main data model and is not merged between entries. It’s used primarily for improving efficiency of operations and for experimentation.
§Returns
Returns Some(&RawData) containing the serialized metadata if present,
or None if no metadata has been set.
§Example
let builder = Entry::builder("root_id");
assert!(builder.metadata().is_none());
let builder = builder.set_metadata(r#"{"custom": "data"}"#);
assert!(builder.metadata().is_some());Sourcepub fn set_height(self, height: u64) -> Self
pub fn set_height(self, height: u64) -> Self
Set the height for this entry in the main tree DAG.
§Arguments
height- The height value for this entry
Sourcepub fn set_height_mut(&mut self, height: u64) -> &mut Self
pub fn set_height_mut(&mut self, height: u64) -> &mut Self
Mutable reference version of set_height.
Sourcepub fn set_subtree_height(
self,
subtree_name: impl Into<String>,
height: Option<u64>,
) -> Self
pub fn set_subtree_height( self, subtree_name: impl Into<String>, height: Option<u64>, ) -> Self
Set the height for this entry in a specific subtree’s DAG.
If the subtree does not exist, it will be created with no data (None).
§Arguments
subtree_name- The name of the subtreeheight- The height value for this entry in the subtree
Sourcepub fn set_subtree_height_mut(
&mut self,
subtree_name: impl Into<String>,
height: Option<u64>,
) -> &mut Self
pub fn set_subtree_height_mut( &mut self, subtree_name: impl Into<String>, height: Option<u64>, ) -> &mut Self
Mutable reference version of set_subtree_height.
Sourcepub fn build(self) -> Result<Entry>
pub fn build(self) -> Result<Entry>
Build and return the final immutable Entry.
This method:
- Sorts all parent lists in both the main tree and subtrees
- Sorts the subtrees list by name
- Removes any empty subtrees
- Creates the immutable
Entry - Validates the entry structure
- Returns the validated entry or an error
After calling this method, the builder is consumed and cannot be used again.
The returned Entry is immutable and its parts cannot be modified.
§Returns
Ok(Entry)if the entry is structurally validErr(crate::Error)if the entry fails validation (e.g., root entry with parents)
Trait Implementations§
Source§impl Clone for EntryBuilder
impl Clone for EntryBuilder
Source§fn clone(&self) -> EntryBuilder
fn clone(&self) -> EntryBuilder
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for EntryBuilder
impl RefUnwindSafe for EntryBuilder
impl Send for EntryBuilder
impl Sync for EntryBuilder
impl Unpin for EntryBuilder
impl UnwindSafe for EntryBuilder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> CompatExt for T
impl<T> CompatExt for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more