fn second_word(s: &String) -> &str {
let bytes = s.as_bytes();
let mut k = 0;
let mut n =0;
for (i, &item) in bytes.iter().enumerate() {
if item == b' ' {
k = k + 1;
if k == 1 {
n = i;
}
else if k == 2 {
return &s[1+n..i];
}
}
}
&s[..]
}
the code looks like shit
fn add_unsafe(a: i32, b: i32) -> i32 {
a + b
}
fn add_safer(a: i32, b: i32) -> std::io::Result<i32> {
Ok(add_unsafe(a, b))
}
fn add_option(a: i32, b:i32) -> Option<std::io::Result<i32>> {
Some(add_safer(a, b))
}
fn main() {
println!("{:?}", add_option("4".parse::<i32>().unwrap(), "5".parse::<i32>().unwrap()).unwrap().unwrap());
}
it unwraps