gix_chunk::file

Struct Index

Source
pub struct Index { /* private fields */ }
Expand description

A chunk file providing a table into the parent data.

Implementations§

Source§

impl Index

Source

pub fn from_bytes( data: &[u8], toc_offset: usize, num_chunks: u32, ) -> Result<Self, Error>

Provided a mapped file at the beginning via data, starting at toc_offset decode all chunk information to return an index with num_chunks chunks.

Source§

impl Index

Source

pub const ENTRY_SIZE: usize = 12usize

The size of a single index entry in bytes

Source

pub const EMPTY_SIZE: usize = 12usize

The smallest possible size of an index, consisting only of the sentinel value pointing past itself.

Source

pub const fn size_for_entries(num_entries: usize) -> usize

Returns the size in bytes an index with num_entries would take.

Source

pub fn offset_by_id(&self, kind: Id) -> Result<Range<Offset>, Error>

Find a chunk of kind and return its offset into the data if found

Source

pub fn usize_offset_by_id(&self, kind: Id) -> Result<Range<usize>, Error>

Find a chunk of kind and return its offset as usize range into the data if found.

§Panics
  • if the usize conversion fails, which isn’t expected as memory maps can’t be created if files are too large to require such offsets.
Source

pub fn validated_usize_offset_by_id<T>( &self, kind: Id, validate: impl FnOnce(Range<usize>) -> T, ) -> Result<T, Error>

Like Index::usize_offset_by_id() but with support for validation and transformation using a function.

Source

pub fn data_by_id<'a>( &self, data: &'a [u8], kind: Id, ) -> Result<&'a [u8], Error>

Find a chunk of kind and return its data slice based on its offset.

Source

pub fn highest_offset(&self) -> Offset

Return the end offset lf the last chunk, which is the highest offset as well. It’s definitely available as we have one or more chunks.

Source§

impl Index

Writing

Source

pub fn for_writing() -> Self

Create a new index whose sole purpose is to be receiving chunks using plan_chunk() and to be written to an output using into_write()

Source

pub fn plan_chunk(&mut self, chunk: Id, exact_size_on_disk: u64)

Plan to write a new chunk as part of the index when into_write() is called.

Source

pub fn planned_storage_size(&self) -> u64

Return the total size of all planned chunks thus far.

Source

pub fn num_chunks(&self) -> usize

Return the amount of chunks we currently know.

Source

pub fn into_write<W>(self, out: W, current_offset: usize) -> Result<Chunk<W>>
where W: Write,

After planning all chunks call this method with the destination to write the chunks to. Use the Chunk writer to write each chunk in order. current_offset is the byte position at which out will continue writing.

Auto Trait Implementations§

§

impl Freeze for Index

§

impl RefUnwindSafe for Index

§

impl Send for Index

§

impl Sync for Index

§

impl Unpin for Index

§

impl UnwindSafe for Index

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.