pub struct Hasher { /* private fields */ }Implementations§
Source§impl Hasher
impl Hasher
Sourcepub fn new() -> Self
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:falseIgnore all whitespaces. This will remove all whitespaces from the input file when generating the hash.
-
no_eof:falseSkip 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();Sourcepub fn eol(self, eol: impl Into<String>) -> Self
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");Sourcepub fn ignore_whitespaces(self, ignore_whitespaces: bool) -> Self
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.
Sourcepub fn no_eof(self, no_eof: bool) -> Self
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);Sourcepub fn hash_file(
&self,
file_in: impl AsRef<Path>,
file_out: Option<impl AsRef<Path>>,
) -> String
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"))
);