3 releases
0.1.2 | Mar 31, 2022 |
---|---|
0.1.1 | Mar 31, 2022 |
0.1.0 | Mar 31, 2022 |
#1450 in Rust patterns
22 downloads per month
8KB
138 lines
sha2-derive
This crate provides a simple Hashable
trait that can be derived easily.
As of now, the derive macro only works on structs.
Example
use sha2_derive::*;
#[derive(Hashable)]
struct User {
username: String,
age: u8,
timestamps: Vec<u64>,
}
fn main() {
let user = User {
username: String::from("Mubelotix"),
age: 42,
timestamps: vec![1, 2, 3],
};
let hash = user.hash();
}
Implementing Hashable on a custom type
struct CustomType {
// fields
}
impl Hashable for CustomType {
fn update_hasher(&self, hasher: &mut impl sha2::Digest) {
todo!()
}
}
License: MIT
lib.rs
:
This crate provides a simple Hashable
trait that can be derived easily.
As of now, the derive macro only works on structs.
Example
use sha2_derive::*;
#[derive(Hashable)]
struct User {
username: String,
age: u8,
timestamps: Vec<u64>,
}
fn main() {
let user = User {
username: String::from("Mubelotix"),
age: 42,
timestamps: vec![1, 2, 3],
};
let hash = user.hash();
}
Implementing Hashable on a custom type
struct CustomType {
// fields
}
impl Hashable for CustomType {
fn update_hasher(&self, hasher: &mut impl sha2::Digest) {
todo!()
}
}
Dependencies
~445KB
~10K SLoC