pub struct Tree {
pub name: SmallVec<[u8; 23]>,
pub id: ObjectId,
pub num_entries: Option<u32>,
pub children: Vec<Tree>,
}
Expand description
A structure to associate object ids of a tree with sections in the index entries list.
It allows to more quickly build trees by avoiding as it can quickly re-use portions of the index and its associated tree ids if there was no change to them. Portions of this tree are invalidated as the index is changed.
Fields§
§name: SmallVec<[u8; 23]>
The name of the tree/directory, or empty if it’s the root tree.
id: ObjectId
The id of the directory tree of the associated tree object.
num_entries: Option<u32>
The amount of non-tree items in this directory tree, including sub-trees, recursively.
The value of the top-level tree is thus equal to the value of the total amount of entries.
If None
, the tree is considered invalid and needs to be refreshed
children: Vec<Tree>
The child-trees below the current tree.
Implementations§
source§impl Tree
impl Tree
sourcepub fn write_to(&self, out: impl Write) -> Result<(), Error>
pub fn write_to(&self, out: impl Write) -> Result<(), Error>
Serialize this instance to out
.
Examples found in repository?
src/write.rs (line 102)
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
fn write_extensions<T>(
&self,
mut write: CountBytes<T>,
offset_to_extensions: u32,
extensions: Extensions,
) -> std::io::Result<(Vec<(extension::Signature, u32)>, T)>
where
T: std::io::Write,
{
type WriteExtFn<'a> = &'a dyn Fn(&mut dyn std::io::Write) -> Option<std::io::Result<extension::Signature>>;
let extensions: &[WriteExtFn<'_>] = &[
&|write| {
extensions
.should_write(extension::tree::SIGNATURE)
.and_then(|signature| self.tree().map(|tree| tree.write_to(write).map(|_| signature)))
},
&|write| {
self.is_sparse()
.then(|| extension::sparse::write_to(write).map(|_| extension::sparse::SIGNATURE))
},
];
let mut offset_to_previous_ext = offset_to_extensions;
let mut out = Vec::with_capacity(5);
for write_ext in extensions {
if let Some(signature) = write_ext(&mut write).transpose()? {
let offset_past_ext = write.count;
let ext_size = offset_past_ext - offset_to_previous_ext - (extension::MIN_SIZE as u32);
offset_to_previous_ext = offset_past_ext;
out.push((signature, ext_size));
}
}
Ok((out, write.inner))
}
Trait Implementations§
source§impl PartialEq<Tree> for Tree
impl PartialEq<Tree> for Tree
impl Eq for Tree
impl StructuralEq for Tree
impl StructuralPartialEq for Tree
Auto Trait Implementations§
impl RefUnwindSafe for Tree
impl Send for Tree
impl Sync for Tree
impl Unpin for Tree
impl UnwindSafe for Tree
Blanket Implementations§
§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Checks if this value is equivalent to the given key. Read more