Skip to main content

Bucket

Struct Bucket 

Source
pub struct Bucket<'a> { /* private fields */ }
Expand description

A borrowed view over a single bucket: the parsed header plus the backing bytes, with slot-table resolution.

Bucket layout, reverse-engineered from libnsfdb_bucket.c:

+------------------+ offset 0
| header (66 B)    |
+------------------+
| slot data ...    |  slot bytes live here, addressed by absolute
|                  |  offset from the bucket start
+------------------+
| slot-index table |  number_of_slots entries, 4 bytes each,
|                  |  stored BACK-TO-FRONT: slot 0 occupies the last
|                  |  4 bytes before the footer. Each entry is
|                  |  [u16 offset][u16 size] (offset at the lower
|                  |  address, size at the higher).
+------------------+ size - footer_size
| footer           |
+------------------+ size

Slot indices on disk are 1-based (libnsfdb_bucket_get_slot rejects index 0 and looks up slot_index - 1); RRV bucket-slot entries carry the 1-based value, so Bucket::slot takes it as-is.

Implementations§

Source§

impl<'a> Bucket<'a>

Source

pub fn parse(bytes: &'a [u8]) -> Result<Self, NsfError>

Parse a bucket from a buffer positioned at the bucket’s file offset. The buffer may extend past the bucket (e.g. it is the remainder of the whole file); this constructor clamps the view to the bucket’s declared size so slot resolution cannot read into a neighbouring structure.

Source

pub fn header(&self) -> &BucketHeader

The parsed bucket header.

Source

pub fn slot_count(&self) -> u32

Number of slots the bucket declares.

Source

pub fn slot_entry(&self, slot_index: u16) -> Result<BucketSlot, NsfError>

Resolve the slot-index entry for a 1-based slot_index.

Returns NsfError::SlotIndexOutOfRange if the index is zero or beyond the declared slot count, or NsfError::TooShort if the bucket buffer does not actually contain the slot-index table the header advertises (truncated / corrupt bucket).

Source

pub fn slot(&self, slot_index: u16) -> Result<&'a [u8], NsfError>

Return the raw bytes of the slot at the 1-based slot_index.

Bounds-checks the slot’s (offset, size) against the bucket so a corrupt slot-index table cannot read out of bounds; returns NsfError::TooShort in that case.

Trait Implementations§

Source§

impl<'a> Debug for Bucket<'a>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Bucket<'a>

§

impl<'a> RefUnwindSafe for Bucket<'a>

§

impl<'a> Send for Bucket<'a>

§

impl<'a> Sync for Bucket<'a>

§

impl<'a> Unpin for Bucket<'a>

§

impl<'a> UnsafeUnpin for Bucket<'a>

§

impl<'a> UnwindSafe for Bucket<'a>

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.