Hasher

Struct Hasher 

Source
pub struct Hasher { /* private fields */ }

Implementations§

Source§

impl Hasher

Source

pub fn new() -> Self

Create new Hasher instance with default options.

§Defaults

If not overwritten by the fluent API, the following defaults are valid:

  • eol: "\n"

    End-of-line sequence, will be appended to each normalized line for hashing.

  • ignore_whitespaces: false

    Ignore all whitespaces. This will remove all whitespaces from the input file when generating the hash.

  • no_eof: false

    Skip last end-of-line on end-of-file. If this is set to true, no trailing EOL will be appended at the end of the file.

§Example
use normalized_hash::Hasher;
let hasher = Hasher::new();
Source

pub fn eol(self, eol: impl Into<String>) -> Self

Change the eol sequence.

This string will be appended to each normalized line for hashing.

Defaults to "\n".

§Example
use normalized_hash::Hasher;
let hasher = Hasher::new().eol("\r\n");
Source

pub fn ignore_whitespaces(self, ignore_whitespaces: bool) -> Self

Ignore all whitespaces.

This will remove all whitespaces from the input file when generating the hash.

Source

pub fn no_eof(self, no_eof: bool) -> Self

Skip last end-of-line on end-of-file.

If this is set to true, no trailing EOL will be appended at the end of the file.

Defaults to false.

§Example
use normalized_hash::Hasher;
let hasher = Hasher::new().no_eof(true);
Source

pub fn hash_file( &self, file_in: impl AsRef<Path>, file_out: Option<impl AsRef<Path>>, ) -> String

Create hash from a text file, regardless of line endings.

This function reads file_in linewise, replacing whatever line ending is present with a single line feed character (\n). From this, it generates a hash code.

Optionally, it is possible to write the normalized input to file_out.

§Example
use std::path::PathBuf;
    use normalized_hash::Hasher;

    let hash_without_output = Hasher::new()
        .hash_file(PathBuf::from("input.txt"), None::<PathBuf>);

    let hash_with_output = Hasher::new().hash_file(
        PathBuf::from("input.txt"),
        Some(PathBuf::from("output.txt"))
    );

Trait Implementations§

Source§

impl Default for Hasher

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Freeze for Hasher

§

impl RefUnwindSafe for Hasher

§

impl Send for Hasher

§

impl Sync for Hasher

§

impl Unpin for Hasher

§

impl UnwindSafe for Hasher

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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> Same for T

Source§

type Output = T

Should always be Self
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.