scopes and shadowing
This commit is contained in:
parent
319948a16e
commit
1322bfd957
26
src/main.rs
26
src/main.rs
|
@ -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.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue