Skip to main content

Tree

Struct Tree 

Source
pub struct Tree { /* private fields */ }
Expand description

A complete tree with its encoding scheme and per-entry salts kept together. Use Self::from_entries_salted_v4 to supply explicit salts for a new tree; mutations through Self::insert maintain the selected scheme.

Explicit salt mutation is internal, so it cannot corrupt a flat tree:

ⓘ
use heddle_object_model::object::{ContentHash, Tree, TreeEntry};
let mut tree = Tree::new();
if let Ok(entry) = TreeEntry::file("readme", ContentHash::compute(b"text"), false) {
    tree.insert_salted(entry, [7; 32]);
}

Implementations§

Source§

impl Tree

Source

pub fn new() -> Tree

Source

pub fn from_entries(entries: Vec<TreeEntry>) -> Tree

Source

pub fn from_entries_salted_v4( entries: Vec<TreeEntry>, salts: Vec<[u8; 32]>, ) -> Result<Tree, TreeError>

Build a salted V4 tree from entries and their parallel salts.

salts[i] is the salt for entries[i] (before sorting); the pair is sorted together by entry name so the parallel-vector invariant holds. The sticky-salt inheritance policy is a later capture-leg concern — this constructor carries whatever salts it is given.

Source

pub fn try_from_decoded_entries( entries: Vec<TreeEntry>, ) -> Result<Tree, TreeError>

Build a tree from entries that are already in canonical name order.

Unlike Self::from_entries, this does not sort. Decoders use it so eager and streaming paths reject the same out-of-order or duplicate encodings instead of silently canonicalizing them.

Source

pub fn try_from_decoded_entries_salted_v4( entries: Vec<TreeEntry>, salts: Vec<[u8; 32]>, ) -> Result<Tree, TreeError>

Build a salted V4 tree from already-name-ordered entries and their parallel salts. Decoders (HSR1, msgpack v4) use this: it does not sort, so it rejects the same out-of-order/duplicate encodings V3 does.

Source

pub fn scheme(&self) -> TreeScheme

The hashing scheme this tree’s id is computed under.

Source

pub fn salts(&self) -> &[[u8; 32]]

The parallel per-entry salt vector (empty for V3 trees).

Source

pub fn salt_at(&self, index: usize) -> Option<[u8; 32]>

The salt for the entry at index (V4 only), or None for V3 / out of range.

Source

pub fn validate(&self) -> Result<(), TreeError>

Source

pub fn entries(&self) -> &[TreeEntry]

Source

pub fn get(&self, name: &str) -> Option<&TreeEntry>

Source

pub fn insert(&mut self, entry: TreeEntry)

Source

pub fn remove(&mut self, name: &str) -> Option<TreeEntry>

Source

pub fn is_empty(&self) -> bool

Source

pub fn len(&self) -> usize

Source

pub fn hash(&self) -> ContentHash

Source

pub fn v4_leaf_hash_at(&self, index: usize) -> Option<ContentHash>

The salted per-entry leaf commitment for the entry at index, or None for a V3 tree / out-of-range index. This is the name-free handle a redacted serve projection is keyed by; capture-time entry-visibility authoring resolves a path to its enclosing tree + this leaf hash.

Source

pub fn v4_leaf_hash_for(&self, name: &str) -> Option<ContentHash>

The salted leaf commitment for the entry named name, or None if the name is absent or this is a V3 tree.

Source

pub fn iter(&self) -> impl Iterator<Item = &TreeEntry>

Source

pub fn get_path(&self, path: &Path) -> Option<&TreeEntry>

Source§

impl Tree

Source§

impl Tree

Source

pub fn encode_canonical(&self) -> Result<Vec<u8>, TreeStreamError>

Encode this tree as an uncompressed canonical body: HTR4 for a V3 flat tree, HSR1 for a V4 salted tree. Scheme-total: a V4 tree is NEVER emitted through the salt-less HTR4 body.

Source

pub fn decode_canonical(data: &[u8]) -> Result<Tree, TreeStreamError>

Decode a complete canonical body. Dispatches on the body magic: HTR4 → flat V3 decode; HSR1 → salted V4 decode. A redacted projection (HRT1) is rejected here — it is serve-only and must never be read as a full tree.

Source

pub fn encode_canonical_blocked( &self, level: i32, min_size: usize, ) -> Result<Vec<u8>, TreeStreamError>

Encode block-compressed HTR4, falling back to raw v4 when the complete object would not be smaller. Callers apply the small-tree policy.

Source§

impl Tree

Source

pub fn encode_lean(&self) -> Result<Vec<u8>, TreeStreamError>

Encode a cheap HLR1 materialized anchor. The content hash deliberately stays outside the body and must be supplied by the object store while decoding.

Source

pub fn decode_lean( data: &[u8], expected: ContentHash, ) -> Result<Tree, TreeStreamError>

Decode a complete HLR1 anchor and validate it against its object key.

Source§

impl Tree

Source

pub fn decode_canonical_streamed(data: &[u8]) -> Result<Tree, TreeStreamError>

Decode HTR4 through the streaming reader and collect the eager Tree.

Trait Implementations§

Source§

impl Clone for Tree

Source§

fn clone(&self) -> Tree

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Tree

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Default for Tree

Source§

fn default() -> Tree

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Tree

Source§

fn deserialize<D>( deserializer: D, ) -> Result<Tree, <D as Deserializer<'de>>::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Eq for Tree

Source§

impl IntoIterator for Tree

Source§

type Item = TreeEntry

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<TreeEntry>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> <Tree as IntoIterator>::IntoIter

Creates an iterator from a value. Read more
Source§

impl<'a> IntoIterator for &'a Tree

Source§

type Item = &'a TreeEntry

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, TreeEntry>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> <&'a Tree as IntoIterator>::IntoIter

Creates an iterator from a value. Read more
Source§

impl PartialEq for Tree

Source§

fn eq(&self, other: &Tree) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for Tree

Source§

fn serialize<S>( &self, serializer: S, ) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Tree

Source§

impl TryFrom<EncodedTreeV2> for Tree

Source§

type Error = TreeError

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

fn try_from( encoded: EncodedTreeV2, ) -> Result<Tree, <Tree as TryFrom<EncodedTreeV2>>::Error>

Performs the conversion.

Auto Trait Implementations§

§

impl Freeze for Tree

§

impl RefUnwindSafe for Tree

§

impl Send for Tree

§

impl Sync for Tree

§

impl Unpin for Tree

§

impl UnsafeUnpin for Tree

§

impl UnwindSafe for Tree

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where 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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

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

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

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

Source§

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.
Source§

impl<T> WithSubscriber for T

Source§

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
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more