Skip to main content

ContentChunk

Struct ContentChunk 

Source
pub struct ContentChunk<const BODY_SIZE: usize = DEFAULT_BODY_SIZE> { /* private fields */ }
Expand description

A content-addressed chunk with configurable body size.

This type represents a chunk of data whose address is derived from the hash of its contents. It is immutable once created.

Implementations§

Source§

impl<const BODY_SIZE: usize> ContentChunk<BODY_SIZE>

Source

pub fn new(data: impl Into<Bytes>) -> Result<Self>

Create a new content chunk with the given data.

This function automatically calculates the span based on the data length.

§Arguments
  • data - The raw data content to encapsulate in the chunk.
§Returns

A Result containing the new ContentChunk, or an error if creation fails.

Source

pub fn with_address( data: impl Into<Bytes>, address: ChunkAddress, ) -> Result<Self>

Create a new ContentChunk with a pre-computed address.

This function is useful when the address is already known, for example when retrieving a chunk from a database.

§Arguments
  • data - The raw data content to encapsulate in the chunk.
  • address - The pre-computed address of the chunk.
§Returns

A Result containing the new ContentChunk, or an error if creation fails.

Source

pub const fn from_body(body: BmtBody<BODY_SIZE>) -> Self

Create a ContentChunk from a pre-existing BmtBody.

This is an advanced method for when you already have a BmtBody, such as when reconstructing chunks from storage or building intermediate nodes in a merkle tree.

Source

pub fn from_body_with_address( body: BmtBody<BODY_SIZE>, address: ChunkAddress, ) -> Self

Create a ContentChunk from a pre-existing BmtBody with a known address.

This is an advanced method for when you already have both the body and know the chunk’s address (e.g., when reconstructing from storage).

Trait Implementations§

Source§

impl<'a, const BODY_SIZE: usize> Arbitrary<'a> for ContentChunk<BODY_SIZE>

Available on crate features arbitrary only.
Source§

fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self>

Generate an arbitrary value of Self from the given unstructured data. Read more
Source§

fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>

Generate an arbitrary value of Self from the entirety of the given unstructured data. Read more
Source§

fn size_hint(depth: usize) -> (usize, Option<usize>)

Get a size hint for how many bytes out of an Unstructured this type needs to construct itself. Read more
Source§

fn try_size_hint( depth: usize, ) -> Result<(usize, Option<usize>), MaxRecursionReached>

Get a size hint for how many bytes out of an Unstructured this type needs to construct itself. Read more
Source§

impl<const BODY_SIZE: usize> BmtChunk for ContentChunk<BODY_SIZE>

Source§

fn span(&self) -> u64

Get the span of the chunk data
Source§

impl<const BODY_SIZE: usize> Chunk for ContentChunk<BODY_SIZE>

Source§

type Header = ContentChunkHeader

The header type for this chunk
Source§

fn address(&self) -> &ChunkAddress

Get the address of this chunk
Source§

fn data(&self) -> &Bytes

Get the raw data contained in this chunk
Source§

fn size(&self) -> usize

Get the total size of this chunk in bytes
Source§

fn header(&self) -> &Self::Header

Get the header for this chunk
Source§

fn verify(&self, expected: &ChunkAddress) -> Result<()>

Verify that this chunk matches an expected address
Source§

impl<const BODY_SIZE: usize> ChunkEncrypt for ContentChunk<BODY_SIZE>

Available on crate feature encryption only.
Source§

fn encrypt_with( &self, key: &EncryptionKey, ) -> Result<EncryptedContentChunk<BODY_SIZE>>

Encrypt this chunk with a caller-provided key.

The returned EncryptedContentChunk contains:

  • chunk: a new ContentChunk whose data is the ciphertext
  • encrypted_ref: the 64-byte reference (new address + decryption key)
let chunk = ContentChunk::<DEFAULT_BODY_SIZE>::new(b"secret data".to_vec()).unwrap();
let encrypted = chunk.encrypt().unwrap();

// The encrypted chunk has a different address
assert_ne!(chunk.address(), encrypted.chunk().address());
Source§

type Encrypted = EncryptedContentChunk<BODY_SIZE>

The encrypted output type.
Source§

fn encrypt(&self) -> Result<Self::Encrypted>

Encrypt with a randomly generated key.
Source§

impl<const BODY_SIZE: usize> ChunkType for ContentChunk<BODY_SIZE>

Source§

const TYPE_ID: ChunkTypeId = super::type_id::ChunkTypeId::CONTENT

The wire-level type identifier for this chunk type. Read more
Source§

const TYPE_NAME: &'static str = "content"

Human-readable name for this chunk type. Read more
Source§

impl<const BODY_SIZE: usize> Clone for ContentChunk<BODY_SIZE>

Source§

fn clone(&self) -> ContentChunk<BODY_SIZE>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<const BODY_SIZE: usize> Debug for ContentChunk<BODY_SIZE>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<const BODY_SIZE: usize> Display for ContentChunk<BODY_SIZE>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<const BODY_SIZE: usize> Eq for ContentChunk<BODY_SIZE>

Source§

impl<const BODY_SIZE: usize> From<ContentChunk<BODY_SIZE>> for AnyChunk<BODY_SIZE>

Source§

fn from(chunk: ContentChunk<BODY_SIZE>) -> Self

Converts to this type from the input type.
Source§

impl<const BODY_SIZE: usize> From<ContentChunk<BODY_SIZE>> for Bytes

Source§

fn from(chunk: ContentChunk<BODY_SIZE>) -> Self

Converts to this type from the input type.
Source§

impl<const BODY_SIZE: usize> PartialEq for ContentChunk<BODY_SIZE>

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<const BODY_SIZE: usize> TryFrom<&[u8]> for ContentChunk<BODY_SIZE>

Source§

type Error = PrimitivesError

The type returned in the event of a conversion error.
Source§

fn try_from(bytes: &[u8]) -> Result<Self>

Performs the conversion.
Source§

impl<const BODY_SIZE: usize> TryFrom<Bytes> for ContentChunk<BODY_SIZE>

Source§

type Error = PrimitivesError

The type returned in the event of a conversion error.
Source§

fn try_from(bytes: Bytes) -> Result<Self>

Performs the conversion.

Auto Trait Implementations§

§

impl<const BODY_SIZE: usize = DEFAULT_BODY_SIZE> !Freeze for ContentChunk<BODY_SIZE>

§

impl<const BODY_SIZE: usize> RefUnwindSafe for ContentChunk<BODY_SIZE>

§

impl<const BODY_SIZE: usize> Send for ContentChunk<BODY_SIZE>

§

impl<const BODY_SIZE: usize> Sync for ContentChunk<BODY_SIZE>

§

impl<const BODY_SIZE: usize> Unpin for ContentChunk<BODY_SIZE>

§

impl<const BODY_SIZE: usize> UnsafeUnpin for ContentChunk<BODY_SIZE>

§

impl<const BODY_SIZE: usize> UnwindSafe for ContentChunk<BODY_SIZE>

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> ChunkSerialization for T
where T: Chunk,

Source§

fn serialize_with_prefix(&self) -> Bytes

Serialize this chunk with its type ID and version prefix
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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