13: Add solutions for section "errors".

[?]
Aaw9nJhsNmfzFih9mKyNw9mV8CgERXJkRa1kK1Kx3LQH
Aug 7, 2021, 10:41 AM
P6TW3CHPDHKG4HL5ZFLWDGSMD2B35LMBQVZJDLX2BVTFRIM75P4AC

Dependencies

Change contents

  • edit in exercises/error_handling/errors6.rs at line 10
    [2.132937][2.132937:132955]()
    // I AM NOT DONE
  • replacement in exercises/error_handling/errors6.rs at line 24
    [2.133326][2.133326:133383]()
    // TODO: add another error conversion function here.
    [2.133326]
    [2.133383]
    fn from_parse_int(err: ParseIntError) -> ParsePosNonzeroError {
    ParsePosNonzeroError::ParseInt(err)
    }
  • replacement in exercises/error_handling/errors6.rs at line 33
    [2.133478][2.133478:133632]()
    // TODO: change this to return an appropriate error instead of panicking
    // when `parse()` returns an error.
    let x: i64 = s.parse().unwrap();
    [2.133478]
    [2.133632]
    let x: i64 = s.parse()
    .map_err(ParsePosNonzeroError::from_parse_int)?;
  • edit in exercises/error_handling/errors5.rs at line 6
    [2.135266][2.135266:135284]()
    // I AM NOT DONE
  • replacement in exercises/error_handling/errors5.rs at line 12
    [2.135411][2.135411:135452]()
    fn main() -> Result<(), ParseIntError> {
    [2.135411]
    [2.135452]
    fn main() -> Result<(), Box<dyn error::Error>> {
  • replacement in exercises/error_handling/errors4.rs at line 4
    [2.136640][2.136640:136657]()
    // I AM NOT DONE
    [2.136640]
    [2.136657]
    use std::cmp::Ordering::{Less, Equal, Greater};
  • replacement in exercises/error_handling/errors4.rs at line 17
    [2.136903][2.136903:136952]()
    Ok(PositiveNonzeroInteger(value as u64))
    [2.136903]
    [2.136952]
    match value.cmp(&0) {
    Less => Err(CreationError::Negative),
    Equal => Err(CreationError::Zero),
    Greater => Ok(PositiveNonzeroInteger(value as u64)),
    }
  • edit in exercises/error_handling/errors3.rs at line 6
    [2.137509][2.137509:137527]()
    // I AM NOT DONE
  • replacement in exercises/error_handling/errors3.rs at line 9
    [2.137558][2.137558:137570]()
    fn main() {
    [2.137558]
    [2.137570]
    fn main() -> Result<(), ParseIntError> {
  • edit in exercises/error_handling/errors3.rs at line 21
    [2.137848]
    [2.137848]
    Ok(())
  • edit in exercises/error_handling/errors2.rs at line 18
    [2.139102][2.139102:139120]()
    // I AM NOT DONE
  • replacement in exercises/error_handling/errors2.rs at line 26
    [2.139322][2.139322:139367]()
    Ok(qty * cost_per_item + processing_fee)
    [2.139322]
    [2.139367]
    Ok(qty? * cost_per_item + processing_fee)
  • replacement in exercises/error_handling/errors1.rs at line 9
    [2.140152][2.140152:140233]()
    // I AM NOT DONE
    pub fn generate_nametag_text(name: String) -> Option<String> {
    [2.140152]
    [2.140233]
    pub fn generate_nametag_text(name: String) -> Result<String, String> {
  • replacement in exercises/error_handling/errors1.rs at line 11
    [2.140257][2.140257:140306]()
    Some(format!("Hi! My name is {}", name))
    [2.140257]
    [2.140306]
    Ok(format!("Hi! My name is {}", name))
  • replacement in exercises/error_handling/errors1.rs at line 14
    [2.140358][2.140358:140371]()
    None
    [2.140358]
    [2.140371]
    Err(String::from("`name` was empty; it must be nonempty."))
  • replacement in exercises/error_handling/errors1.rs at line 29
    [2.140731][2.140731:140782]()
    Some("Hi! My name is Beyoncé".into())
    [2.140731]
    [2.140782]
    Ok("Hi! My name is Beyoncé".into())