Skip to main content

DataChunk

Trait DataChunk 

Source
pub trait DataChunk
where Self: Sized,
{ // Required methods fn data_ref(&self) -> &[u8] ; fn hash_ref(&self) -> &Hash; // Provided methods fn hash(&self) -> Hash { ... } fn encrypt(&self) -> Result<EncryptedDataChunk> { ... } fn decrypt(&self, key: &Hash) -> Result<SerializedDataChunk> { ... } fn borrow(&self) -> BorrowedDataChunk<'_> { ... } fn serialize(&self) -> Result<SerializedDataChunk> { ... } fn into_bytes(self) -> Bytes { ... } fn into_owned(self) -> OwnedDataChunk { ... } fn try_as<T: Archive>(self) -> Result<TypedDataChunk<Self, T>> where T::Archived: for<'a> CheckBytes<HighValidator<'a, Error>> { ... } }
Expand description

Represents any representation of a chunk of data.

§Invariants

Implementers must treat the bytes and hash exposed through &self as immutable and stable. In practice this means:

  • Repeated calls to Self::data_ref must point to the same logical bytes while self is borrowed.
  • Repeated calls to Self::hash_ref must return the hash for those same bytes.
  • Neither value may change through interior mutability while self is borrowed.

TypedDataChunk relies on this contract for its unchecked deref fast path.

Required Methods§

Source

fn data_ref(&self) -> &[u8]

Returns a stable view of the underlying bytes.

Source

fn hash_ref(&self) -> &Hash

Returns a stable view of the hash corresponding to Self::data_ref.

Provided Methods§

Source

fn hash(&self) -> Hash

Source

fn encrypt(&self) -> Result<EncryptedDataChunk>

Source

fn decrypt(&self, key: &Hash) -> Result<SerializedDataChunk>

Source

fn borrow(&self) -> BorrowedDataChunk<'_>

Source

fn serialize(&self) -> Result<SerializedDataChunk>

Source

fn into_bytes(self) -> Bytes

Transforms this DataChunk into Bytes.

Source

fn into_owned(self) -> OwnedDataChunk

Copies this DataChunk into a new OwnedDataChunk.

Source

fn try_as<T: Archive>(self) -> Result<TypedDataChunk<Self, T>>
where T::Archived: for<'a> CheckBytes<HighValidator<'a, Error>>,

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§