Skip to content

Commit bc3e42e

Browse files
committed
rolled up various changes
1 parent 6b2db67 commit bc3e42e

File tree

4 files changed

+21
-8
lines changed

4 files changed

+21
-8
lines changed

debug-macro.rs

+15-1
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,27 @@ const DEBUG: bool = true;
33

44
#[allow(unused)]
55
macro_rules! debug {
6+
($msg:literal) => {
7+
if DEBUG {
8+
eprintln!("{}", $msg as &'static str);
9+
}
10+
};
611
($msg:literal, $x:expr) => {
712
if DEBUG {
813
eprintln!("{}: {:?}", $msg as &'static str, $x);
914
}
1015
};
1116
}
1217

18+
#[allow(unused)]
19+
fn bad_fib(n: u64) -> u64 {
20+
match n {
21+
i@(0|1) => i,
22+
n => bad_fib(n - 1) + bad_fib(n - 2),
23+
}
24+
}
25+
1326
fn main() {
14-
debug!("running", Some(5));
27+
debug!("running");
28+
debug!("running", "yep");
1529
}

histogram.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use std::io::Read;
1111
use std::iter::FromIterator;
1212

1313
#[derive(Clone, Debug)]
14-
struct Histogram<T: Hash + Eq>(HashMap<T, usize>);
14+
struct Histogram<T: Hash + Eq, u64>(HashMap<T, C>);
1515

1616
impl<T: Hash + Eq> Histogram<T> {
1717
fn histogram<I>(values: I) -> Self
@@ -27,9 +27,9 @@ impl<T: Hash + Eq> Histogram<T> {
2727
}
2828

2929
impl<T: Hash + Eq + Ord> Histogram<T> {
30-
fn graph<'a>(&'a self) -> Vec<(&'a T, usize)> {
30+
fn graph<'a>(&'a self) -> Vec<(&'a T, u64)> {
3131
let Histogram(h) = self;
32-
let mut result: Vec<(&T, usize)> =
32+
let mut result: Vec<(&T, u64)> =
3333
h.iter().map(|(k, v)| (k, *v)).collect();
3434
result.sort();
3535
result

macro-tt.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
macro_rules! reargument {
2-
($x:tt ! ( $($_:tt),* )) => ($x!("huh"))
2+
($x:ident ! ( $($_:tt),* )) => ($x!("huh"))
33
}
44

55
fn main() {

square-macro.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
macro_rules! square {
22
($s:expr) => {{
3-
let n = $s;
4-
n * n
3+
($s) * ($s)
54
}};
65
}
76

87
fn main() {
9-
let mut n = 3;
8+
let mut n = 3_u8;
109
println!("3**2={}", square!(n));
1110
println!("4**2={}", square!({n += 1; n}));
1211
}

0 commit comments

Comments
 (0)