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.