Skip to main content

LoadedBlob

Enum LoadedBlob 

Source
pub enum LoadedBlob {
    Inline(Vec<u8>),
    Chunked(ChunkedBlob),
}
Expand description

A blob’s top-level object, read from the store exactly once and held so a caller needing several views of the same blob — byte length, bounded prefix, full content — pays a single top-level read_object instead of one per view. diff --stat is the motivating caller: its text-vs-binary sniff needs a prefix, then either the length (binary row) or the full content (text row), and taking each view through a separate store-level read re-read (and re-hash-verified) the same object two times per changed file, a per-entry cost that dominates a many-small-files diffstat (#624).

Chunk objects are still read on demand: Self::len reads none, Self::prefix reads only leading chunks, Self::into_content reads them all.

One read stays undeduped by design: Self::prefix on a chunked blob reads the leading chunk(s) to sniff, and Self::into_content reads every chunk (including that same leading one) to reassemble — a caller doing both, as diff --stat does, reads the first chunk twice. Caching it would need either interior mutability or a consuming-prefix API, to save an O(1) read on an O(n-chunks) path; not worth it (#624).

Variants§

§

Inline(Vec<u8>)

An inline Blob: its full content, already in hand.

§

Chunked(ChunkedBlob)

A ChunkedBlob manifest: content lives in chunk objects, read only when a view needs them.

Implementations§

Source§

impl LoadedBlob

Source

pub fn load<S: ObjectSource + ?Sized>( store: &S, hash: &Hash, ) -> WorktreeResult<Self>

Read the top-level object addressed by hash — one store read.

§Errors
Source

pub fn len(&self) -> u64

Content byte length from what is already in hand — an inline blob’s data length, a chunked blob’s manifest total_size — no chunk reads. total_size is trustworthy without re-verifying against the chunks: every reassembly path enforces it via ChunkedBlob::check_reassembled_size, so a manifest with a wrong total_size cannot have been durably written (#550).

Source

pub fn is_empty(&self) -> bool

Whether the content is zero bytes long.

Source

pub fn prefix<S: ObjectSource + ?Sized>( &self, store: &S, max_len: usize, ) -> WorktreeResult<Cow<'_, [u8]>>

Up to max_len leading content bytes. Inline data is borrowed (no copy, no reads); a chunked blob reads only as many leading chunks as it takes to cover max_len, then stops — one chunk in practice, since every chunk but possibly the last is at least crate::chunker::MIN_SIZE bytes, well above the sniff windows callers use (e.g. crate::ops::diff::BINARY_SNIFF_LEN).

§Errors
Source

pub fn into_content<S: ObjectSource + ?Sized>( self, store: &S, ) -> WorktreeResult<Vec<u8>>

The full content: inline data as-is (no further reads), a chunked blob reassembled by reading every chunk, with the result length enforced against the manifest’s total_size (SPEC-OBJECTS §7).

§Errors
Source

pub fn empty() -> Self

The empty blob: what a diff side with no object (an add’s old side, a delete’s new side) loads as. Zero length, empty prefix, empty content — no store reads.

Trait Implementations§

Source§

impl Debug for LoadedBlob

Source§

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

Formats the value using the given formatter. Read more

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FutureExt for T

Source§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Source§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more