scopes and shadowing
This commit is contained in:
parent
319948a16e
commit
1322bfd957
29 changed files with 9 additions and 17 deletions
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() {
|
fn main() {
|
||||||
println!("{BANNER}");
|
let a = 10;
|
||||||
|
println!("beginning a: {a}");
|
||||||
|
{
|
||||||
|
let a = "hello";
|
||||||
|
println!("inner a: {a}");
|
||||||
|
|
||||||
let digest = compute_digest("Hello");
|
let a = true;
|
||||||
println!("digest: {digest:?}");
|
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…
Add table
Add a link
Reference in a new issue