scopes and shadowing

This commit is contained in:
Vincent Batts 2023-01-16 15:42:12 -05:00
parent 319948a16e
commit 1322bfd957
29 changed files with 9 additions and 17 deletions

View File

@ -1,20 +1,12 @@
static BANNER: &str = "Welcome to Rust";
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() {
println!("{BANNER}");
let a = 10;
println!("beginning a: {a}");
{
let a = "hello";
println!("inner a: {a}");
let digest = compute_digest("Hello");
println!("digest: {digest:?}");
let a = true;
println!("shadowed a: {a}");
}
println!("ending a: {a}");
}

Binary file not shown.