P6TW3CHPDHKG4HL5ZFLWDGSMD2B35LMBQVZJDLX2BVTFRIM75P4AC
H6XH45OPVRRAAP2N4AK3DCHVVSMVQ6B3MQZYKU7YVCN4O2IJGQUQC
// I AM NOT DONE
// TODO: add another error conversion function here.
fn from_parse_int(err: ParseIntError) -> ParsePosNonzeroError { ParsePosNonzeroError::ParseInt(err) }
fn from_parse_int(err: ParseIntError) -> ParsePosNonzeroError {
ParsePosNonzeroError::ParseInt(err)
}
// TODO: change this to return an appropriate error instead of panicking // when `parse()` returns an error. let x: i64 = s.parse().unwrap();
// TODO: change this to return an appropriate error instead of panicking
// when `parse()` returns an error.
let x: i64 = s.parse().unwrap();
let x: i64 = s.parse() .map_err(ParsePosNonzeroError::from_parse_int)?;
let x: i64 = s.parse()
.map_err(ParsePosNonzeroError::from_parse_int)?;
fn main() -> Result<(), ParseIntError> {
fn main() -> Result<(), Box<dyn error::Error>> {
use std::cmp::Ordering::{Less, Equal, Greater};
Ok(PositiveNonzeroInteger(value as u64))
match value.cmp(&0) { Less => Err(CreationError::Negative), Equal => Err(CreationError::Zero), Greater => Ok(PositiveNonzeroInteger(value as u64)), }
match value.cmp(&0) {
Less => Err(CreationError::Negative),
Equal => Err(CreationError::Zero),
Greater => Ok(PositiveNonzeroInteger(value as u64)),
fn main() {
Ok(())
Ok(qty * cost_per_item + processing_fee)
Ok(qty? * cost_per_item + processing_fee)
// I AM NOT DONEpub fn generate_nametag_text(name: String) -> Option<String> {
pub fn generate_nametag_text(name: String) -> Option<String> {
pub fn generate_nametag_text(name: String) -> Result<String, String> {
Some(format!("Hi! My name is {}", name))
Ok(format!("Hi! My name is {}", name))
None
Err(String::from("`name` was empty; it must be nonempty."))
Some("Hi! My name is Beyoncé".into())
Ok("Hi! My name is Beyoncé".into())