Skip to main content

Tree

Struct Tree 

Source
pub struct Tree<'a, R> { /* private fields */ }
Expand description

A handle on one tree of a volume, for searching or iterating it.

Borrowed from the Volume rather than owning anything, so a caller moves between trees without reopening the filesystem — and so that every block either reads goes through the one chunk map and the one checksum check.

Implementations§

Source§

impl<'a, R: Read + Seek> Tree<'a, R>

Source

pub fn root(&self) -> TreeRoot

Which tree this is, and where it begins.

Source

pub fn for_each_item<F>(&mut self, visit: F) -> Result<(), ReadError>
where F: FnMut(&DiskKey, &[u8]) -> bool,

Visit every item, in key order.

The closure answers whether to keep going, so a caller looking for one thing stops where it finds it rather than reading the rest of the tree.

§Errors

Whatever reading a block does, and the tree-shape refusals this module’s documentation lists.

Source

pub fn for_each_item_from<F>( &mut self, from: DiskKey, visit: F, ) -> Result<(), ReadError>
where F: FnMut(&DiskKey, &[u8]) -> bool,

Visit every item at or after from, in key order.

The descent goes straight to the first item at or after the key rather than walking the tree from its start, which is what makes “the entries of this directory” one descent instead of a scan.

§Errors

As for_each_item.

Source

pub fn for_each_block<F>(&mut self, visit: F) -> Result<(), ReadError>
where F: FnMut(&TreeBlock) -> bool,

Visit every block of the tree, in the order a depth-first descent meets them.

Every block is fetched through the chunk map and its checksum verified before the closure sees it, so a walk that completes is a statement that every block of the tree verified. The items are bounds-checked on the way past whether or not the closure looks at them, which is what makes this a verification pass rather than a header read.

§Errors

As for_each_item.

Source

pub fn find_first(&mut self, key: DiskKey) -> Result<Option<Located>, ReadError>

The first item at or after key, or None where the tree holds none.

§Errors

As for_each_item.

Source

pub fn find_exact(&mut self, key: DiskKey) -> Result<Option<Located>, ReadError>

The item stored under exactly key, or None where there is none.

§Errors

As for_each_item.

Source

pub fn find_at_or_before( &mut self, key: DiskKey, ) -> Result<Option<Located>, ReadError>

The last item at or before key, or None where every item in the tree is above it.

The search a range needs, where find_first is the one a point needs. A record keyed by where a run begins covers everything up to the next one, so the record covering a position is the last one at or before it — and asking for the first at or after would find the record covering the next position and skip the one wanted. That is how a file’s extents are keyed, and reading from an offset in the middle of one is the case that makes the difference visible.

One descent, so it costs the height of the tree rather than a scan.

§Errors

As for_each_item.

Source

pub fn count_items(&mut self) -> Result<u64, ReadError>

How many items the tree holds, having read and verified every block on the way.

§Errors

As for_each_item.

Auto Trait Implementations§

§

impl<'a, R> Freeze for Tree<'a, R>

§

impl<'a, R> RefUnwindSafe for Tree<'a, R>
where R: RefUnwindSafe,

§

impl<'a, R> Send for Tree<'a, R>
where R: Send,

§

impl<'a, R> Sync for Tree<'a, R>
where R: Sync,

§

impl<'a, R> Unpin for Tree<'a, R>

§

impl<'a, R> UnsafeUnpin for Tree<'a, R>

§

impl<'a, R> !UnwindSafe for Tree<'a, R>

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.