File tree Expand file tree Collapse file tree 8 files changed +191
-0
lines changed Expand file tree Collapse file tree 8 files changed +191
-0
lines changed Original file line number Diff line number Diff line change @@ -58,3 +58,14 @@ Modules
5858
5959- ` cargo run -p day-11-modules --bin nested-submodules `
6060- ` cargo run -p day-11-traffic-light `
61+
62+ ### Day 12
63+
64+ - ` cargo run -p day-12-impl-tostring `
65+ - ` cargo run -p day-12-impl-asref-str `
66+
67+ ### Day 13
68+
69+ - ` cargo run -p day-13-option `
70+ - ` cargo run -p day-13-result `
71+ - ` cargo run -p day-13-question-mark `
Original file line number Diff line number Diff line change 1+ [package ]
2+ name = " day-13-option"
3+ version = " 0.0.0"
4+ edition = " 2021"
5+
6+ # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+
8+ [dependencies ]
Original file line number Diff line number Diff line change 1+ use std:: time:: Instant ;
2+
3+ fn main ( ) {
4+ let some = returns_some ( ) ;
5+ println ! ( "{:?}" , some) ;
6+
7+ let none = returns_none ( ) ;
8+ println ! ( "{:?}" , none) ;
9+
10+ let default_string = "Default value" . to_owned ( ) ;
11+
12+ let unwrap_or = returns_none ( ) . unwrap_or ( default_string) ;
13+ println ! ( "returns_none().unwrap_or(...): {:?}" , unwrap_or) ;
14+
15+ let unwrap_or_else = returns_none ( )
16+ . unwrap_or_else ( || format ! ( "Default value from a function at time {:?}" , Instant :: now( ) ) ) ;
17+
18+ println ! (
19+ "returns_none().unwrap_or_else(|| {{...}}): {:?}" ,
20+ unwrap_or_else
21+ ) ;
22+
23+ let unwrap_or_default = returns_none ( ) . unwrap_or_default ( ) ;
24+
25+ println ! (
26+ "returns_none().unwrap_or_default(): {:?}" ,
27+ unwrap_or_default
28+ ) ;
29+
30+ let match_value = match returns_some ( ) {
31+ Some ( val) => val,
32+ None => "My default value" . to_owned ( ) ,
33+ } ;
34+
35+ println ! ( "match {{...}}: {:?}" , match_value) ;
36+
37+ if let Some ( val) = returns_some ( ) {
38+ println ! ( "if let : {:?}" , val) ;
39+ }
40+ }
41+
42+ fn returns_some ( ) -> Option < String > {
43+ Some ( "my string" . to_owned ( ) )
44+ }
45+
46+ fn returns_none ( ) -> Option < String > {
47+ None
48+ }
Original file line number Diff line number Diff line change 1+ [package ]
2+ name = " day-13-question-mark"
3+ version = " 0.0.0"
4+ edition = " 2021"
5+
6+ # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+
8+ [dependencies ]
9+ markdown = " 0.3.0"
Original file line number Diff line number Diff line change 1+ use std:: fs:: read_to_string;
2+
3+ fn main ( ) -> Result < ( ) , std:: io:: Error > {
4+ let html = render_markdown ( "./README.md" ) ?;
5+ println ! ( "{}" , html) ;
6+ Ok ( ( ) )
7+ }
8+
9+ fn render_markdown ( file : & str ) -> Result < String , std:: io:: Error > {
10+ let source = read_to_string ( file) ?;
11+ Ok ( markdown:: to_html ( & source) )
12+ }
Original file line number Diff line number Diff line change 1+ [package ]
2+ name = " day-13-result"
3+ version = " 0.0.0"
4+ edition = " 2021"
5+
6+ # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+
8+ [dependencies ]
Original file line number Diff line number Diff line change 1+ fn main ( ) {
2+ let value = returns_ok ( ) ;
3+ println ! ( "{:?}" , value) ;
4+
5+ let value = returns_err ( ) ;
6+ println ! ( "{:?}" , value) ;
7+ }
8+
9+ fn returns_ok ( ) -> Result < String , MyError > {
10+ Ok ( "This turned out great!" . to_owned ( ) )
11+ }
12+
13+ fn returns_err ( ) -> Result < String , MyError > {
14+ Err ( MyError ( "This failed horribly." . to_owned ( ) ) )
15+ }
16+
17+ #[ derive( Debug ) ]
18+ struct MyError ( String ) ;
You can’t perform that action at this time.
0 commit comments