Struct ps_datachunk::owned::OwnedDataChunk
source · pub struct OwnedDataChunk { /* private fields */ }
Expand description
represents an owned chunk of data
Implementations§
source§impl OwnedDataChunk
impl OwnedDataChunk
pub fn data_ref(&self) -> &[u8] ⓘ
pub fn hash_ref(&self) -> &[u8] ⓘ
pub fn hash(&self) -> Arc<Hash>
sourcepub fn from_parts(data: Vec<u8>, hash: Arc<Hash>) -> Self
pub fn from_parts(data: Vec<u8>, hash: Arc<Hash>) -> Self
Creates an OwnedDataChunk from its constituent parts
§Safety
hash
must be the hash ofdata
- use
from_data()
if you cannot ensure this
sourcepub fn from_data(data: Vec<u8>) -> Self
pub fn from_data(data: Vec<u8>) -> Self
calculates the hash of data
and returns an OwnedDataChunk
sourcepub fn from_data_ref_and_hash(data: &[u8], hash: Arc<Hash>) -> Self
pub fn from_data_ref_and_hash(data: &[u8], hash: Arc<Hash>) -> Self
creates an OwnedDataChunk
with given data
and hash
sourcepub fn from_data_ref(data: &[u8]) -> Self
pub fn from_data_ref(data: &[u8]) -> Self
creates an OwnedDataChunk
with given data
sourcepub fn serialize_into(self) -> Vec<u8>
pub fn serialize_into(self) -> Vec<u8>
converts this OwnedDataChunk
into a Vec<u8>
- extends
self.hash
- returns
self.data
sourcepub fn serialize(&self) -> Vec<u8>
pub fn serialize(&self) -> Vec<u8>
serializes this OwnedDataChunk
into a newly allocated Vec<u8>
- allocated a new
Vec<u8>
- copies
self.data
into the newVec<u8>
- copies
self.hash
into the newVec<u8>
- returns the new
Vec<u8>
sourcepub fn deserialize_from(data: Vec<u8>) -> Result<Self>
pub fn deserialize_from(data: Vec<u8>) -> Result<Self>
- converts a
Vec<u8>
into anOwnedDataChunk
- performs hash validation
sourcepub fn deserialize(data: &[u8]) -> Result<Self>
pub fn deserialize(data: &[u8]) -> Result<Self>
Copies data
into a new Vec<u8>
and deserializes it into an OwnedDataChunk
.
sourcepub fn decrypt_bytes(
encrypted: &[u8],
key: &[u8],
compressor: &Compressor,
) -> Result<Self>
pub fn decrypt_bytes( encrypted: &[u8], key: &[u8], compressor: &Compressor, ) -> Result<Self>
Decrypts into an OwnedDataChunk
with the given key
- performs hash validation
- fails if
key
not correct
sourcepub fn decrypt(&self, key: &[u8], compressor: &Compressor) -> Result<Self>
pub fn decrypt(&self, key: &[u8], compressor: &Compressor) -> Result<Self>
Decrypts an OwnedDataChunk
with the given key
.
- performs hash validation
- fails if
key
not correct
sourcepub fn encrypt_serialized_bytes(
bytes: &[u8],
compressor: &Compressor,
) -> Result<EncryptedDataChunk>
pub fn encrypt_serialized_bytes( bytes: &[u8], compressor: &Compressor, ) -> Result<EncryptedDataChunk>
Encrypts a serialized DataChunk.
sourcepub fn encrypt(&self, compressor: &Compressor) -> Result<EncryptedDataChunk>
pub fn encrypt(&self, compressor: &Compressor) -> Result<EncryptedDataChunk>
Encrypts this DataChunk.
sourcepub fn encrypt_mut(
&mut self,
compressor: &Compressor,
) -> Result<EncryptedDataChunk>
pub fn encrypt_mut( &mut self, compressor: &Compressor, ) -> Result<EncryptedDataChunk>
Encrypts this DataChunk.
- optimized by using
self.data
as the serialization buffer
Trait Implementations§
source§impl Clone for OwnedDataChunk
impl Clone for OwnedDataChunk
source§fn clone(&self) -> OwnedDataChunk
fn clone(&self) -> OwnedDataChunk
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl DataChunkTrait for OwnedDataChunk
impl DataChunkTrait for OwnedDataChunk
fn data_ref(&self) -> &[u8] ⓘ
fn hash_ref(&self) -> &[u8] ⓘ
fn hash(&self) -> HashCow<'_>
fn encrypt(&self, compressor: &Compressor) -> Result<EncryptedDataChunk>
fn decrypt(&self, key: &[u8], compressor: &Compressor) -> Result<OwnedDataChunk>
fn to_datachunk(&self) -> DataChunk<'_>
fn align(&self) -> AlignedDataChunk
fn borrow(&self) -> BorrowedDataChunk<'_>
fn to_owned(&self) -> OwnedDataChunk
fn try_as<T: Archive>(&self) -> Result<TypedDataChunk<'_, T>>
source§impl Debug for OwnedDataChunk
impl Debug for OwnedDataChunk
source§impl From<&OwnedDataChunk> for AlignedDataChunk
impl From<&OwnedDataChunk> for AlignedDataChunk
source§fn from(value: &OwnedDataChunk) -> Self
fn from(value: &OwnedDataChunk) -> Self
Converts to this type from the input type.
source§impl<'lt> From<DataChunk<'lt>> for OwnedDataChunk
impl<'lt> From<DataChunk<'lt>> for OwnedDataChunk
source§impl<'lt> From<OwnedDataChunk> for DataChunk<'lt>
impl<'lt> From<OwnedDataChunk> for DataChunk<'lt>
source§fn from(chunk: OwnedDataChunk) -> Self
fn from(chunk: OwnedDataChunk) -> Self
Converts to this type from the input type.
source§impl Hash for OwnedDataChunk
impl Hash for OwnedDataChunk
source§impl Into<OwnedDataChunk> for &AlignedDataChunk
impl Into<OwnedDataChunk> for &AlignedDataChunk
source§fn into(self) -> OwnedDataChunk
fn into(self) -> OwnedDataChunk
Converts this type into the (usually inferred) input type.
source§impl Ord for OwnedDataChunk
impl Ord for OwnedDataChunk
source§fn cmp(&self, other: &OwnedDataChunk) -> Ordering
fn cmp(&self, other: &OwnedDataChunk) -> Ordering
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
source§impl PartialEq for OwnedDataChunk
impl PartialEq for OwnedDataChunk
source§impl PartialOrd for OwnedDataChunk
impl PartialOrd for OwnedDataChunk
impl Eq for OwnedDataChunk
impl StructuralPartialEq for OwnedDataChunk
Auto Trait Implementations§
impl Freeze for OwnedDataChunk
impl RefUnwindSafe for OwnedDataChunk
impl Send for OwnedDataChunk
impl Sync for OwnedDataChunk
impl Unpin for OwnedDataChunk
impl UnwindSafe for OwnedDataChunk
Blanket Implementations§
source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
§type ArchivedMetadata = ()
type ArchivedMetadata = ()
The archived version of the pointer metadata for this type.
source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
Converts some archived metadata to the pointer metadata for itself.
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
Mutably borrows from an owned value. Read more
source§impl<T> CallHasher for T
impl<T> CallHasher for T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)source§impl<F, W, T, D> Deserialize<With<T, W>, D> for F
impl<F, W, T, D> Deserialize<With<T, W>, D> for F
source§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Gets the layout of the type.