File tree 4 files changed +21
-8
lines changed
4 files changed +21
-8
lines changed Original file line number Diff line number Diff line change @@ -3,13 +3,27 @@ const DEBUG: bool = true;
3
3
4
4
#[ allow( unused) ]
5
5
macro_rules! debug {
6
+ ( $msg: literal) => {
7
+ if DEBUG {
8
+ eprintln!( "{}" , $msg as & ' static str ) ;
9
+ }
10
+ } ;
6
11
( $msg: literal, $x: expr) => {
7
12
if DEBUG {
8
13
eprintln!( "{}: {:?}" , $msg as & ' static str , $x) ;
9
14
}
10
15
} ;
11
16
}
12
17
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
+
13
26
fn main ( ) {
14
- debug ! ( "running" , Some ( 5 ) ) ;
27
+ debug ! ( "running" ) ;
28
+ debug ! ( "running" , "yep" ) ;
15
29
}
Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ use std::io::Read;
11
11
use std:: iter:: FromIterator ;
12
12
13
13
#[ derive( Clone , Debug ) ]
14
- struct Histogram < T : Hash + Eq > ( HashMap < T , usize > ) ;
14
+ struct Histogram < T : Hash + Eq , u64 > ( HashMap < T , C > ) ;
15
15
16
16
impl < T : Hash + Eq > Histogram < T > {
17
17
fn histogram < I > ( values : I ) -> Self
@@ -27,9 +27,9 @@ impl<T: Hash + Eq> Histogram<T> {
27
27
}
28
28
29
29
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 ) > {
31
31
let Histogram ( h) = self ;
32
- let mut result: Vec < ( & T , usize ) > =
32
+ let mut result: Vec < ( & T , u64 ) > =
33
33
h. iter ( ) . map ( |( k, v) | ( k, * v) ) . collect ( ) ;
34
34
result. sort ( ) ;
35
35
result
Original file line number Diff line number Diff line change 1
1
macro_rules! reargument {
2
- ( $x: tt ! ( $( $_: tt) ,* ) ) => ( $x!( "huh" ) )
2
+ ( $x: ident ! ( $( $_: tt) ,* ) ) => ( $x!( "huh" ) )
3
3
}
4
4
5
5
fn main ( ) {
Original file line number Diff line number Diff line change 1
1
macro_rules! square {
2
2
( $s: expr) => { {
3
- let n = $s;
4
- n * n
3
+ ( $s) * ( $s)
5
4
} } ;
6
5
}
7
6
8
7
fn main ( ) {
9
- let mut n = 3 ;
8
+ let mut n = 3_u8 ;
10
9
println ! ( "3**2={}" , square!( n) ) ;
11
10
println ! ( "4**2={}" , square!( { n += 1 ; n} ) ) ;
12
11
}
You can’t perform that action at this time.
0 commit comments