From f94e0a2217ff81161b4edf23cac64cfd65668a1e Mon Sep 17 00:00:00 2001 From: Nick Babcock Date: Sat, 25 Jan 2025 19:33:15 -0600 Subject: [PATCH] Add hwysum example --- examples/hwysum.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 examples/hwysum.rs diff --git a/examples/hwysum.rs b/examples/hwysum.rs new file mode 100644 index 0000000..90ee70c --- /dev/null +++ b/examples/hwysum.rs @@ -0,0 +1,25 @@ +use highway::HighwayHash; + +// This is a simple example of how to hash data from stdin using a +// HighwayHasher. Analagous to `shasum` and `md5sum` but using HighwayHash. +// +// ```bash +// cargo run --release --example hwysum < README.md +// ``` +#[cfg(feature = "std")] +fn main() { + let stdin = std::io::stdin(); + let mut lock = stdin.lock(); + let mut hasher = highway::HighwayHasher::new(highway::Key::default()); + let _ = std::io::copy(&mut lock, &mut hasher); + let hash = hasher.finalize256(); + println!( + "{:016x}{:016x}{:016x}{:016x}", + hash[0], hash[1], hash[2], hash[3] + ); +} + +#[cfg(not(feature = "std"))] +fn main() { + println!("This example requires the 'std' feature to be enabled."); +}