From b9ff88759833841cf59635790c25d0348a798685 Mon Sep 17 00:00:00 2001 From: ahgamut <41098605+ahgamut@users.noreply.github.com> Date: Wed, 7 Sep 2022 11:06:14 +0530 Subject: [PATCH] comment out errors/missings --- src/bin/attribute_cfg_custom.rs | 4 +-- src/bin/conversion_from_into.rs | 13 ---------- src/bin/custom_types_enum.rs | 5 ---- src/bin/error_abort_unwind.rs | 6 ++--- ...rror_multiple_error_types_option_result.rs | 10 -------- src/bin/error_option_unwrap_defaults.rs | 6 ----- src/bin/error_result_enter_question_mark.rs | 25 ------------------- src/bin/error_result_result_map.rs | 10 +++----- src/bin/flow_control_if_let.rs | 22 ++++++++-------- src/bin/flow_control_match_guard.rs | 2 +- src/bin/hello_print.rs | 2 +- src/bin/meta_doc.rs | 5 ++-- src/bin/mod_use.rs | 8 +++--- src/bin/scope_lifetime_explicit.rs | 4 +-- src/bin/scope_lifetime_static_lifetime.rs | 2 +- src/bin/std_arc.rs | 5 ++-- src/bin/std_hash_alt_key_types.rs | 6 ++--- src/bin/std_misc_threads.rs | 6 ++--- src/bin/trait_impl_trait.rs | 3 ++- src/bin/variable_bindings_declare.rs | 2 +- src/bin/variable_bindings_mut.rs | 2 +- 21 files changed, 45 insertions(+), 103 deletions(-) diff --git a/src/bin/attribute_cfg_custom.rs b/src/bin/attribute_cfg_custom.rs index df97dcd..68c1ac7 100644 --- a/src/bin/attribute_cfg_custom.rs +++ b/src/bin/attribute_cfg_custom.rs @@ -1,7 +1,7 @@ // ./src/attribute/cfg/custom.md - -#[cfg(some_condition)] +/* +#[cfg(some_condition)]*/ fn conditional_function() { println!("condition met!"); } diff --git a/src/bin/conversion_from_into.rs b/src/bin/conversion_from_into.rs index 5781070..67d6b86 100644 --- a/src/bin/conversion_from_into.rs +++ b/src/bin/conversion_from_into.rs @@ -19,19 +19,6 @@ fn part0() { println!("My number is {:?}", num); } -use std::convert::From; - -#[derive(Debug)] -struct Number { - value: i32, -} - -impl From for Number { - fn from(item: i32) -> Self { - Number { value: item } - } -} - fn part1() { let int = 5; // Try removing the type declaration diff --git a/src/bin/custom_types_enum.rs b/src/bin/custom_types_enum.rs index de44467..1ff9554 100644 --- a/src/bin/custom_types_enum.rs +++ b/src/bin/custom_types_enum.rs @@ -62,11 +62,6 @@ fn part1() { let x = Operations::Add; } -enum VeryVerboseEnumOfThingsToDoWithNumbers { - Add, - Subtract, -} - impl VeryVerboseEnumOfThingsToDoWithNumbers { fn run(&self, x: i32, y: i32) -> i32 { match self { diff --git a/src/bin/error_abort_unwind.rs b/src/bin/error_abort_unwind.rs index 13b441d..166eb12 100644 --- a/src/bin/error_abort_unwind.rs +++ b/src/bin/error_abort_unwind.rs @@ -1,7 +1,7 @@ // ./src/error/abort_unwind.md - +/* fn drink(beverage: &str) { // You shouldn't drink too much sugary beverages. if beverage == "lemonade" { @@ -15,7 +15,7 @@ fn part0() { drink("water"); drink("lemonade"); } - +*/ #[cfg(panic = "unwind")] fn ah(){ println!("Spit it out!!!!");} @@ -34,7 +34,7 @@ fn part1() { } pub fn main() { - part0(); + // part0(); part1(); } diff --git a/src/bin/error_multiple_error_types_option_result.rs b/src/bin/error_multiple_error_types_option_result.rs index 7e5e702..bce28ef 100644 --- a/src/bin/error_multiple_error_types_option_result.rs +++ b/src/bin/error_multiple_error_types_option_result.rs @@ -23,16 +23,6 @@ fn part0() { // Error 2: the element doesn't parse to a number } -use std::num::ParseIntError; - -fn double_first(vec: Vec<&str>) -> Result, ParseIntError> { - let opt = vec.first().map(|first| { - first.parse::().map(|n| 2 * n) - }); - - opt.map_or(Ok(None), |r| r.map(Some)) -} - fn part1() { let numbers = vec!["42", "93", "18"]; let empty = vec![]; diff --git a/src/bin/error_option_unwrap_defaults.rs b/src/bin/error_option_unwrap_defaults.rs index 46acc89..32aeac2 100644 --- a/src/bin/error_option_unwrap_defaults.rs +++ b/src/bin/error_option_unwrap_defaults.rs @@ -20,8 +20,6 @@ fn part0() { // TODO: uncomment the line above to see the compiler error } -#[derive(Debug)] -enum Fruit { Apple, Orange, Banana, Kiwi, Lemon } fn part1() { let apple = Some(Fruit::Apple); @@ -43,8 +41,6 @@ fn part1() { // first_available_fruit: Some(Kiwi) } -#[derive(Debug)] -enum Fruit { Apple, Orange, Banana, Kiwi, Lemon } fn part2() { let mut my_fruit: Option = None; @@ -58,8 +54,6 @@ fn part2() { // TODO: uncomment the line above to see the compiler error } -#[derive(Debug)] -enum Fruit { Apple, Orange, Banana, Kiwi, Lemon } fn part3() { let mut my_fruit: Option = None; diff --git a/src/bin/error_result_enter_question_mark.rs b/src/bin/error_result_enter_question_mark.rs index b57e6c5..016d52a 100644 --- a/src/bin/error_result_enter_question_mark.rs +++ b/src/bin/error_result_enter_question_mark.rs @@ -22,32 +22,7 @@ fn part0() { print(multiply("t", "2")); } -// To compile and run this example without errors, while using Cargo, change the value -// of the `edition` field, in the `[package]` section of the `Cargo.toml` file, to "2015". - -use std::num::ParseIntError; - -fn multiply(first_number_str: &str, second_number_str: &str) -> Result { - let first_number = try!(first_number_str.parse::()); - let second_number = try!(second_number_str.parse::()); - - Ok(first_number * second_number) -} - -fn print(result: Result) { - match result { - Ok(n) => println!("n is {}", n), - Err(e) => println!("Error: {}", e), - } -} - -fn part1() { - print(multiply("10", "2")); - print(multiply("t", "2")); -} - pub fn main() { part0(); - part1(); } diff --git a/src/bin/error_result_result_map.rs b/src/bin/error_result_result_map.rs index d335afb..c9bab7c 100644 --- a/src/bin/error_result_result_map.rs +++ b/src/bin/error_result_result_map.rs @@ -35,18 +35,16 @@ fn part0() { print(tt); } -use std::num::ParseIntError; - // As with `Option`, we can use combinators such as `map()`. // This function is otherwise identical to the one above and reads: // Modify n if the value is valid, otherwise pass on the error. -fn multiply(first_number_str: &str, second_number_str: &str) -> Result { +fn multiply2(first_number_str: &str, second_number_str: &str) -> Result { first_number_str.parse::().and_then(|first_number| { second_number_str.parse::().map(|second_number| first_number * second_number) }) } -fn print(result: Result) { +fn print2(result: Result) { match result { Ok(n) => println!("n is {}", n), Err(e) => println!("Error: {}", e), @@ -55,11 +53,11 @@ fn print(result: Result) { fn part1() { // This still presents a reasonable answer. - let twenty = multiply("10", "2"); + let twenty = multiply2("10", "2"); print(twenty); // The following now provides a much more helpful error message. - let tt = multiply("t", "2"); + let tt = multiply2("t", "2"); print(tt); } diff --git a/src/bin/flow_control_if_let.rs b/src/bin/flow_control_if_let.rs index 0e0f4b8..0a541ed 100644 --- a/src/bin/flow_control_if_let.rs +++ b/src/bin/flow_control_if_let.rs @@ -37,7 +37,7 @@ fn part0() { } // Our example enum -enum Foo { +enum Foo1 { Bar, Baz, Qux(u32) @@ -45,42 +45,42 @@ enum Foo { fn part1() { // Create example variables - let a = Foo::Bar; - let b = Foo::Baz; - let c = Foo::Qux(100); + let a = Foo1::Bar; + let b = Foo1::Baz; + let c = Foo1::Qux(100); // Variable a matches Foo::Bar - if let Foo::Bar = a { + if let Foo1::Bar = a { println!("a is foobar"); } // Variable b does not match Foo::Bar // So this will print nothing - if let Foo::Bar = b { + if let Foo1::Bar = b { println!("b is foobar"); } // Variable c matches Foo::Qux which has a value // Similar to Some() in the previous example - if let Foo::Qux(value) = c { + if let Foo1::Qux(value) = c { println!("c is {}", value); } // Binding also works with `if let` - if let Foo::Qux(value @ 100) = c { + if let Foo1::Qux(value @ 100) = c { println!("c is one hundred"); } } // This enum purposely neither implements nor derives PartialEq. // That is why comparing Foo::Bar == a fails below. -enum Foo {Bar} +enum Foo2 {Bar} fn part2() { - let a = Foo::Bar; + let a = Foo2::Bar; // Variable a matches Foo::Bar - if Foo::Bar == a { + if let Foo2::Bar = a { // ^-- this causes a compile-time error. Use `if let` instead. println!("a is foobar"); } diff --git a/src/bin/flow_control_match_guard.rs b/src/bin/flow_control_match_guard.rs index 49c814e..05546b8 100644 --- a/src/bin/flow_control_match_guard.rs +++ b/src/bin/flow_control_match_guard.rs @@ -26,7 +26,7 @@ fn part1() { match number { i if i == 0 => println!("Zero"), i if i > 0 => println!("Greater than zero"), - // _ => unreachable!("Should never happen."), + _ => unreachable!("Should never happen."), // TODO ^ uncomment to fix compilation } } diff --git a/src/bin/hello_print.rs b/src/bin/hello_print.rs index 7c25404..aed87e5 100644 --- a/src/bin/hello_print.rs +++ b/src/bin/hello_print.rs @@ -40,7 +40,7 @@ fn part0() { // Rust even checks to make sure the correct number of arguments are // used. - println!("My name is {0}, {1} {0}", "Bond"); +// println!("My name is {0}, {1} {0}", "Bond"); // FIXME ^ Add the missing argument: "James" // Only types that implement fmt::Display can be formatted with `{}`. User- diff --git a/src/bin/meta_doc.rs b/src/bin/meta_doc.rs index 2a91720..63136b3 100644 --- a/src/bin/meta_doc.rs +++ b/src/bin/meta_doc.rs @@ -1,6 +1,6 @@ // ./src/meta/doc.md - +/* #![crate_name = "doc"] /// A human being is represented here @@ -47,8 +47,9 @@ fn part0() { // Example from the futures-rs library #[doc(hidden)] pub use self::async_await::*; +*/ pub fn main() { - part0(); + // part0(); } diff --git a/src/bin/mod_use.rs b/src/bin/mod_use.rs index 3c9d746..077b2be 100644 --- a/src/bin/mod_use.rs +++ b/src/bin/mod_use.rs @@ -1,6 +1,6 @@ // ./src/mod/use.md - +/* use crate::deeply::nested::{ my_first_function, my_second_function, @@ -44,10 +44,10 @@ fn part1() { } function(); -} +}*/ pub fn main() { - part0(); - part1(); + // part0(); + // part1(); } diff --git a/src/bin/scope_lifetime_explicit.rs b/src/bin/scope_lifetime_explicit.rs index 3b35080..03e6cdf 100644 --- a/src/bin/scope_lifetime_explicit.rs +++ b/src/bin/scope_lifetime_explicit.rs @@ -10,10 +10,10 @@ fn print_refs<'a, 'b>(x: &'a i32, y: &'b i32) { // A function which takes no arguments, but has a lifetime parameter `'a`. fn failed_borrow<'a>() { - let _x = 12; + // let _x = 12; // ERROR: `_x` does not live long enough - let y: &'a i32 = &_x; + // let y: &'a i32 = &_x; // Attempting to use the lifetime `'a` as an explicit type annotation // inside the function will fail because the lifetime of `&_x` is shorter // than that of `y`. A short lifetime cannot be coerced into a longer one. diff --git a/src/bin/scope_lifetime_static_lifetime.rs b/src/bin/scope_lifetime_static_lifetime.rs index 04dec08..b9371cf 100644 --- a/src/bin/scope_lifetime_static_lifetime.rs +++ b/src/bin/scope_lifetime_static_lifetime.rs @@ -14,7 +14,7 @@ fn part0() { // oops, &i only has the lifetime defined by the scope of // part0(), so it's not 'static: - print_it(&i); + // print_it(&i); } pub fn main() { diff --git a/src/bin/std_arc.rs b/src/bin/std_arc.rs index caefc89..7ba4eaf 100644 --- a/src/bin/std_arc.rs +++ b/src/bin/std_arc.rs @@ -1,6 +1,6 @@ // ./src/std/arc.md - +/* use std::time::Duration; use std::sync::Arc; use std::thread; @@ -24,8 +24,9 @@ fn part0() { // Make sure all Arc instances are printed from spawned threads. thread::sleep(Duration::from_secs(1)); } +*/ pub fn main() { - part0(); + // part0(); } diff --git a/src/bin/std_hash_alt_key_types.rs b/src/bin/std_hash_alt_key_types.rs index 815c5e9..d87538c 100644 --- a/src/bin/std_hash_alt_key_types.rs +++ b/src/bin/std_hash_alt_key_types.rs @@ -1,6 +1,6 @@ // ./src/std/hash/alt_key_types.md - +/* use std::collections::HashMap; // Eq requires that you derive PartialEq on the type. @@ -56,9 +56,9 @@ fn part0(){ try_logon(&accounts, "j.everyman", "psasword123"); try_logon(&accounts, "j.everyman", "password123"); -} +}*/ pub fn main() { - part0(); + // part0(); } diff --git a/src/bin/std_misc_threads.rs b/src/bin/std_misc_threads.rs index 7408821..5f93be8 100644 --- a/src/bin/std_misc_threads.rs +++ b/src/bin/std_misc_threads.rs @@ -1,6 +1,6 @@ // ./src/std_misc/threads.md - +/* use std::thread; const NTHREADS: u32 = 10; @@ -21,9 +21,9 @@ fn part0() { // Wait for the thread to finish. Returns a result. let _ = child.join(); } -} +} */ pub fn main() { - part0(); + // part0(); } diff --git a/src/bin/trait_impl_trait.rs b/src/bin/trait_impl_trait.rs index ea1aafd..af77d4c 100644 --- a/src/bin/trait_impl_trait.rs +++ b/src/bin/trait_impl_trait.rs @@ -15,6 +15,7 @@ fn parse_csv_document(src: R) -> std::io::Result> } +/* fn parse_csv_document(src: impl std::io::BufRead) -> std::io::Result>> { src.lines() .map(|line| { @@ -27,7 +28,7 @@ fn parse_csv_document(src: impl std::io::BufRead) -> std::io::Result> -} +} */ use std::iter; use std::vec::IntoIter; diff --git a/src/bin/variable_bindings_declare.rs b/src/bin/variable_bindings_declare.rs index 40af0ae..577187e 100644 --- a/src/bin/variable_bindings_declare.rs +++ b/src/bin/variable_bindings_declare.rs @@ -17,7 +17,7 @@ fn part0() { let another_binding; // Error! Use of uninitialized binding - println!("another binding: {}", another_binding); + // println!("another binding: {}", another_binding); // FIXME ^ Comment out this line another_binding = 1; diff --git a/src/bin/variable_bindings_mut.rs b/src/bin/variable_bindings_mut.rs index 63897b6..bec538e 100644 --- a/src/bin/variable_bindings_mut.rs +++ b/src/bin/variable_bindings_mut.rs @@ -13,7 +13,7 @@ fn part0() { println!("After mutation: {}", mutable_binding); // Error! - _immutable_binding += 1; + // _immutable_binding += 1; // FIXME ^ Comment out this line }