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>
impl<const BODY_SIZE: usize> ContentChunk<BODY_SIZE>
Sourcepub fn with_address(
data: impl Into<Bytes>,
address: ChunkAddress,
) -> Result<Self>
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.
Sourcepub const fn from_body(body: BmtBody<BODY_SIZE>) -> Self
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.
Sourcepub fn from_body_with_address(
body: BmtBody<BODY_SIZE>,
address: ChunkAddress,
) -> Self
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.
impl<'a, const BODY_SIZE: usize> Arbitrary<'a> for ContentChunk<BODY_SIZE>
arbitrary only.Source§fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self>
fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self>
Self from the given unstructured data. Read moreSource§fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>
fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>
Self from the entirety of the given
unstructured data. Read moreSource§fn size_hint(depth: usize) -> (usize, Option<usize>)
fn size_hint(depth: usize) -> (usize, Option<usize>)
Unstructured this type
needs to construct itself. Read moreSource§fn try_size_hint(
depth: usize,
) -> Result<(usize, Option<usize>), MaxRecursionReached>
fn try_size_hint( depth: usize, ) -> Result<(usize, Option<usize>), MaxRecursionReached>
Unstructured this type
needs to construct itself. Read moreSource§impl<const BODY_SIZE: usize> BmtChunk for ContentChunk<BODY_SIZE>
impl<const BODY_SIZE: usize> BmtChunk for ContentChunk<BODY_SIZE>
Source§impl<const BODY_SIZE: usize> Chunk for ContentChunk<BODY_SIZE>
impl<const BODY_SIZE: usize> Chunk for ContentChunk<BODY_SIZE>
Source§fn address(&self) -> &ChunkAddress
fn address(&self) -> &ChunkAddress
Source§impl<const BODY_SIZE: usize> ChunkEncrypt for ContentChunk<BODY_SIZE>
Available on crate feature encryption only.
impl<const BODY_SIZE: usize> ChunkEncrypt for ContentChunk<BODY_SIZE>
encryption only.Source§fn encrypt_with(
&self,
key: &EncryptionKey,
) -> Result<EncryptedContentChunk<BODY_SIZE>>
fn encrypt_with( &self, key: &EncryptionKey, ) -> Result<EncryptedContentChunk<BODY_SIZE>>
Encrypt this chunk with a caller-provided key.
The returned EncryptedContentChunk contains:
chunk: a newContentChunkwhose data is the ciphertextencrypted_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>
type Encrypted = EncryptedContentChunk<BODY_SIZE>
Source§impl<const BODY_SIZE: usize> ChunkType for ContentChunk<BODY_SIZE>
impl<const BODY_SIZE: usize> ChunkType for ContentChunk<BODY_SIZE>
Source§impl<const BODY_SIZE: usize> Clone for ContentChunk<BODY_SIZE>
impl<const BODY_SIZE: usize> Clone for ContentChunk<BODY_SIZE>
Source§fn clone(&self) -> ContentChunk<BODY_SIZE>
fn clone(&self) -> ContentChunk<BODY_SIZE>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<const BODY_SIZE: usize> Debug for ContentChunk<BODY_SIZE>
impl<const BODY_SIZE: usize> Debug for ContentChunk<BODY_SIZE>
Source§impl<const BODY_SIZE: usize> Display for ContentChunk<BODY_SIZE>
impl<const BODY_SIZE: usize> Display for ContentChunk<BODY_SIZE>
impl<const BODY_SIZE: usize> Eq for ContentChunk<BODY_SIZE>
Source§impl<const BODY_SIZE: usize> From<ContentChunk<BODY_SIZE>> for AnyChunk<BODY_SIZE>
impl<const BODY_SIZE: usize> From<ContentChunk<BODY_SIZE>> for AnyChunk<BODY_SIZE>
Source§fn from(chunk: ContentChunk<BODY_SIZE>) -> Self
fn from(chunk: ContentChunk<BODY_SIZE>) -> Self
Source§impl<const BODY_SIZE: usize> From<ContentChunk<BODY_SIZE>> for Bytes
impl<const BODY_SIZE: usize> From<ContentChunk<BODY_SIZE>> for Bytes
Source§fn from(chunk: ContentChunk<BODY_SIZE>) -> Self
fn from(chunk: ContentChunk<BODY_SIZE>) -> Self
Source§impl<const BODY_SIZE: usize> PartialEq for ContentChunk<BODY_SIZE>
impl<const BODY_SIZE: usize> PartialEq for ContentChunk<BODY_SIZE>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> ChunkSerialization for Twhere
T: Chunk,
impl<T> ChunkSerialization for Twhere
T: Chunk,
Source§fn serialize_with_prefix(&self) -> Bytes
fn serialize_with_prefix(&self) -> Bytes
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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