Update description

This commit is contained in:
Grzegorz Dziadkiewicz 2025-01-12 11:50:18 +01:00
parent 72fbb10e2c
commit d8babf9a53
No known key found for this signature in database
GPG key ID: D93C27C4A6448C3D
3 changed files with 19 additions and 16 deletions
exercises/13_error_handling
rustlings-macros
solutions/13_error_handling

View file

@ -1,8 +1,8 @@
// TODOUsing catch-all error types like `Box<dyn Error>` isn't recommended for
// library code where callers might want to make decisions based on the error
// content instead of printing it out or propagating it further. Here, we define
// a custom error type to make it possible for callers to decide what to do next
// when our function returns an error.
// While defining and using a custom error type in library code is recomended
// the ergonomics of the map_err approach presented in errors6 is suboptimal.
// The growing codebase could quickly become obfuscated by error conversions
// sprinkled here and there. Fortunetly, using traits we just learned about,
// we can use one more Rust feature to fix that.
use std::num::ParseIntError;
@ -29,13 +29,16 @@ impl ParsePosNonzeroError {
}
}
// TODO Implement From trait for ParseIntError and CreationError
// TODO Implement From trait for ParseIntError
// impl From<ParseIntError> for ParsePosNonzeroError {
// fn from(err: ParseIntError) -> Self {
// ???
// }
// }
// TODO Implement From trait for CreationError
// ...
#[derive(PartialEq, Debug)]
struct PositiveNonzeroInteger(u64);
@ -49,9 +52,9 @@ impl PositiveNonzeroInteger {
}
fn parse(s: &str) -> Result<Self, ParsePosNonzeroError> {
// Return an appropriate error instead of panicking when `parse()`
// returns an error.
// Don't change this line
let x: i64 = s.parse()?;
// Don't change this line
Self::new(x)?
}
}

View file

@ -760,7 +760,7 @@ The `+` operator can concatenate a `String` with a `&str`."""
name = "errors7"
dir = "13_error_handling"
hint = """
More about relatio between try operator and From Trait:
More about relation between try operator and the From trait:
https://doc.rust-lang.org/std/convert/trait.From.html#examples"""
[[exercises]]

View file

@ -1,8 +1,8 @@
// Using catch-all error types like `Box<dyn Error>` isn't recommended for
// library code where callers might want to make decisions based on the error
// content instead of printing it out or propagating it further. Here, we define
// a custom error type to make it possible for callers to decide what to do next
// when our function returns an error.
// While defining and using a custom error type in library code is recomended
// the ergonomics of the map_err approach presented in errors6 is suboptimal.
// The growing codebase could quickly become obfuscated by error conversions
// sprinkled here and there. Fortunetly, using traits we just learned about,
// we can use one more Rust feature to fix that.
use std::num::ParseIntError;
@ -54,9 +54,9 @@ impl PositiveNonzeroInteger {
}
fn parse(s: &str) -> Result<Self, ParsePosNonzeroError> {
// Return an appropriate error instead of panicking when `parse()`
// returns an error.
// Don't change this line
let x: i64 = s.parse()?;
// Don't change this line
Self::new(x)?
}
}