pub struct Tree {
pub hash: Hash,
pub entries: Vec<TreeEntry>,
}Expand description
A content-addressed tree object. entries are sorted by name.
Fields§
§hash: Hash§entries: Vec<TreeEntry>Implementations§
Source§impl Tree
impl Tree
Sourcepub fn new(entries: Vec<TreeEntry>) -> Result<Self>
pub fn new(entries: Vec<TreeEntry>) -> Result<Self>
Build a tree from its direct children, sorting and computing the hash.
Rejects entry names that would corrupt the canonical preimage (see
validate_entry_name).
Sourcepub fn canonical_bytes(&self) -> Vec<u8> ⓘ
pub fn canonical_bytes(&self) -> Vec<u8> ⓘ
The canonical byte preimage this tree’s hash is computed over: one line
per entry (sorted by name), kind\tname\thash\tmode, joined by \n.
This is also the on-disk serialized form stored (compressed) in the
trees.content column — keeping the stored bytes identical to the hash
recipe means integrity is a single hash_bytes(content) == hash check.
Sourcepub fn from_canonical_bytes(hash: Hash, bytes: &[u8]) -> Result<Self>
pub fn from_canonical_bytes(hash: Hash, bytes: &[u8]) -> Result<Self>
Reconstruct a tree from its canonical byte form (the inverse of
Tree::canonical_bytes). hash is taken as the storage key; callers
that want integrity should compare hash_bytes(bytes) against it.
Parsing is strict: names must pass validate_entry_name, hashes must
be valid hex, and the mode field must round-trip through
[mode_string] exactly. Anything [serialize_entries] could not have
produced is rejected rather than silently mis-parsed — defense against
malicious wire or database bytes.
Sourcepub fn empty_hash() -> Hash
pub fn empty_hash() -> Hash
Hash that represents an empty tree. Useful as a sentinel.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Tree
impl<'de> Deserialize<'de> for Tree
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Forget for Tree
impl Freeze for Tree
impl Move 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> 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> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
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