Struct den::Signature

source ·
pub struct Signature { /* private fields */ }
Expand description

A identifier of a file, much smaller than the file itself.

See crate-level documentation for more details.

Implementations§

source§

impl Signature

source

pub fn parallel_diff(&self, data: &[u8], wp: &WorkerPool) -> Difference

Calculate the Self::diff in parallel using multiple OS threads.

source

pub fn parallel_diff_with_options( &self, data: &[u8], wp: &WorkerPool, data_size_threshold: usize, parallel_block_size: usize ) -> Difference

Calculate the Self::diff in parallel using multiple OS threads.

data_size_threshold is the threshold for how long data has to be before using the parallel implementation. If data is shorter than data_size_threshold, Self::diff is used instead.

parallel_block_size is the size of the blocks data is split into before being sent to other threads.

Panics

Panics if parallel_block_size == 0.

source§

impl Signature

source

pub fn new(block_size: usize) -> SignatureBuilder

Creates a new SignatureBuilder in which data can be added to create a list of hashes for blocks the size of block_size.

I recommend block size 4096 for remote transfers. If small documents are what’s mostly being transmitted, consider 512. Consider running Difference::minify if getting the smallest diff is your concern.

This creates a signature of a resource. The signature takes up much less space than the resource.

Larger block_sizes will take more less to compute but signatures become larger, as if a block’s contents isn’t found, it has to send block_size bytes of data. Smaller block_sizes takes more time to compute, but send data in the Signature. Diffs with smaller block_sizes also have the advantage of interfering less with changes if applied to data other than what’s written to the signature.

The HashAlgorithm is chosen using experience with hasher’s performance and heuristics. You can query the algorithm using Self::algorithm.

Panics

Panics if block_size is 0.

source

pub fn with_algorithm( algorithm: HashAlgorithm, block_size: usize ) -> SignatureBuilder

This will create a new SignatureBuilder with the algorithm. Consider using Self::new if you don’t know exactly what you are doing, as it sets the algorithm for you. You can query the algorithm using Self::algorithm.

See Self::new for more details and insights into how to choose block_size.

Panics

Will panic if HashAlgorithm is of type None* and block_size is larger than the HashAlgorithm. Also panics if block_size is 0.

source

pub const fn algorithm(&self) -> HashAlgorithm

Get the algorithm used by this signature.

source

pub const fn block_size(&self) -> usize

Returns the block size of this signature.

source

pub fn diff(&self, data: &[u8]) -> Difference

Get the Difference between the data the Signature represents and the local data.

This will return a struct which when serialized (using e.g. bincode) is much smaller than data.

Trait Implementations§

source§

impl Clone for Signature

source§

fn clone(&self) -> Signature

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl Debug for Signature

source§

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

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

impl<'de> Deserialize<'de> for Signature

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl PartialEq<Signature> for Signature

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Serialize for Signature

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl Eq for Signature

source§

impl StructuralEq for Signature

source§

impl StructuralPartialEq for Signature

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · 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> ToOwned for Twhere T: Clone,

§

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, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> DeserializeOwned for Twhere T: for<'de> Deserialize<'de>,