comment out errors/missings

This commit is contained in:
ahgamut 2022-09-07 11:06:14 +05:30
parent cfa3e47f54
commit b9ff887598
21 changed files with 45 additions and 103 deletions

View file

@ -1,7 +1,7 @@
// ./src/attribute/cfg/custom.md
#[cfg(some_condition)]
/*
#[cfg(some_condition)]*/
fn conditional_function() {
println!("condition met!");
}

View file

@ -19,19 +19,6 @@ fn part0() {
println!("My number is {:?}", num);
}
use std::convert::From;
#[derive(Debug)]
struct Number {
value: i32,
}
impl From<i32> for Number {
fn from(item: i32) -> Self {
Number { value: item }
}
}
fn part1() {
let int = 5;
// Try removing the type declaration

View file

@ -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 {

View file

@ -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();
}

View file

@ -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<Option<i32>, ParseIntError> {
let opt = vec.first().map(|first| {
first.parse::<i32>().map(|n| 2 * n)
});
opt.map_or(Ok(None), |r| r.map(Some))
}
fn part1() {
let numbers = vec!["42", "93", "18"];
let empty = vec![];

View file

@ -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<Fruit> = 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<Fruit> = None;

View file

@ -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<i32, ParseIntError> {
let first_number = try!(first_number_str.parse::<i32>());
let second_number = try!(second_number_str.parse::<i32>());
Ok(first_number * second_number)
}
fn print(result: Result<i32, ParseIntError>) {
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();
}

View file

@ -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<i32, ParseIntError> {
fn multiply2(first_number_str: &str, second_number_str: &str) -> Result<i32, ParseIntError> {
first_number_str.parse::<i32>().and_then(|first_number| {
second_number_str.parse::<i32>().map(|second_number| first_number * second_number)
})
}
fn print(result: Result<i32, ParseIntError>) {
fn print2(result: Result<i32, ParseIntError>) {
match result {
Ok(n) => println!("n is {}", n),
Err(e) => println!("Error: {}", e),
@ -55,11 +53,11 @@ fn print(result: Result<i32, ParseIntError>) {
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);
}

View file

@ -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");
}

View file

@ -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
}
}

View file

@ -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-

View file

@ -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();
}

View file

@ -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();
}

View file

@ -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.

View file

@ -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() {

View file

@ -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();
}

View file

@ -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();
}

View file

@ -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();
}

View file

@ -15,6 +15,7 @@ fn parse_csv_document<R: std::io::BufRead>(src: R) -> std::io::Result<Vec<Vec<St
.collect() // Collect all lines into a Vec<Vec<String>>
}
/*
fn parse_csv_document(src: impl std::io::BufRead) -> std::io::Result<Vec<Vec<String>>> {
src.lines()
.map(|line| {
@ -27,7 +28,7 @@ fn parse_csv_document(src: impl std::io::BufRead) -> std::io::Result<Vec<Vec<Str
})
})
.collect() // Collect all lines into a Vec<Vec<String>>
}
} */
use std::iter;
use std::vec::IntoIter;

View file

@ -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;

View file

@ -13,7 +13,7 @@ fn part0() {
println!("After mutation: {}", mutable_binding);
// Error!
_immutable_binding += 1;
// _immutable_binding += 1;
// FIXME ^ Comment out this line
}