Skip to content

Commit

Permalink
Add alternate usage instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
ventaquil committed Mar 16, 2024
1 parent 91b7cb1 commit c738a94
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 3 deletions.
15 changes: 14 additions & 1 deletion .cargo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,20 @@ cargo add chksum

## Usage

Use the `chksum` function to calcualate digest of file, directory and so on.
Use the `chksum` function with the desired algorithm to calcualate digest of file, directory and so on.

```rust
use chksum::{chksum, SHA2_256};

let file = File::open(path)?;
let digest = chksum::<SHA2_256>(file)?;
assert_eq!(
digest.to_hex_lowercase(),
"44752f37272e944fd2c913a35342eaccdd1aaf189bae50676b301ab213fc5061"
);
```

Alternatively, use the `chksum` function directly from the chosen hash module.

```rust
use chksum::sha2_256;
Expand Down
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,20 @@ cargo add chksum

## Usage

Use the `chksum` function to calcualate digest of file, directory and so on.
Use the `chksum` function with the desired algorithm to calcualate digest of file, directory and so on.

```rust
use chksum::{chksum, SHA2_256};

let file = File::open(path)?;
let digest = chksum::<SHA2_256>(file)?;
assert_eq!(
digest.to_hex_lowercase(),
"44752f37272e944fd2c913a35342eaccdd1aaf189bae50676b301ab213fc5061"
);
```

Alternatively, use the `chksum` function directly from the chosen hash module.

```rust
use chksum::sha2_256;
Expand Down
22 changes: 21 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,27 @@
//!
//! # Usage
//!
//! Use the [`chksum`] function to calcualate digest of file, directory and so on.
//! Use the [`chksum`] function with the desired algorithm to calcualate digest of file, directory and so on.
//!
//! ```rust
//! # use std::path::Path;
//! use std::fs::File;
//!
//! # use chksum::Result;
//! use chksum::{chksum, SHA2_256};
//!
//! # fn wrapper(path: &Path) -> Result<()> {
//! let file = File::open(path)?;
//! let digest = chksum::<SHA2_256>(file)?;
//! assert_eq!(
//! digest.to_hex_lowercase(),
//! "44752f37272e944fd2c913a35342eaccdd1aaf189bae50676b301ab213fc5061"
//! );
//! # Ok(())
//! # }
//! ```
//!
//! Alternatively, use the `chksum` function directly from the chosen hash module.
//!
//! ```rust
//! # use std::path::Path;
Expand Down

0 comments on commit c738a94

Please sign in to comment.