Skip to main content

TreeBlock

Enum TreeBlock 

Source
pub enum TreeBlock {
    Node {
        header: Header,
        ptrs: Vec<KeyPtr>,
    },
    Leaf {
        header: Header,
        items: Vec<Item>,
        data: Vec<u8>,
    },
}
Expand description

A parsed btrfs tree block: either an internal node or a leaf.

Nodes (level > 0) contain sorted key pointers to child blocks. Leaves (level == 0) contain sorted items whose data payloads can be parsed with crate::items::parse_item_payload.

Variants§

§

Node

Internal node (level > 0): contains key pointers to child blocks.

Fields

§header: Header

The tree block header.

§ptrs: Vec<KeyPtr>

Sorted key pointers to child blocks.

§

Leaf

Leaf node (level == 0): contains items with data payloads.

Fields

§header: Header

The tree block header.

§items: Vec<Item>

Sorted item descriptors (key + offset/size into the data area).

§data: Vec<u8>

The full block data, so item formatters can extract payloads.

Implementations§

Source§

impl TreeBlock

Source

pub fn parse(buf: &[u8]) -> Self

Parse a tree block from a nodesize-length buffer.

Source

pub fn header(&self) -> &Header

Return a reference to the header.

Source

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

For a leaf block, get the data slice for item at index.

The item’s offset field is relative to the start of the data area, which begins right after the header. So the absolute offset in the block buffer is HEADER_SIZE + item.offset.

Auto Trait Implementations§

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

Source§

type Output = T

Should always be Self
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.