oh neat. A three bit digest. The const's are inlined once used
This commit is contained in:
parent
ceda46b8d1
commit
1eff21e93e
31 changed files with 13 additions and 14 deletions
27
src/main.rs
27
src/main.rs
|
@ -1,16 +1,15 @@
|
|||
const DIGEST_SIZE: usize = 3;
|
||||
const ZERO: Option<u8> = Some(42);
|
||||
|
||||
fn compute_digest(text: &str) -> [u8; DIGEST_SIZE] {
|
||||
let mut digest = [ZERO.unwrap_or(0); DIGEST_SIZE];
|
||||
for (idx, &b) in text.as_bytes().iter().enumerate() {
|
||||
digest[idx % DIGEST_SIZE] = digest[idx % DIGEST_SIZE].wrapping_add(b)
|
||||
}
|
||||
return digest;
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let x = 10;
|
||||
let y = 20;
|
||||
|
||||
takes_u32(x);
|
||||
takes_i8(y);
|
||||
takes_u32(y.try_into().unwrap());
|
||||
}
|
||||
|
||||
fn takes_u32(x: u32) -> () {
|
||||
println!("{x}");
|
||||
}
|
||||
|
||||
fn takes_i8(x: i8) -> () {
|
||||
println!("{x}");
|
||||
let digest = compute_digest("Hello");
|
||||
println!("digest: {digest:?}");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue