Random stuff, testing things, and so on.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

31 lines
743 B

fn main() {
let evens = [2, 2, 2, 2, 2];
let res = evens
.iter()
.map(|v| {
if v % 2 == 0 {
Ok(v.to_string())
} else {
Err("No".to_string())
}
})
.collect::<Result<Vec<String>, String>>();
println!("Evens: {:?}", res);
let not_evens = [2, 2, 2, 2, 1, 2];
let res = not_evens
.iter()
.map(|v| {
if v % 2 == 0 {
Ok(v.to_string())
} else {
Err("No".to_string())
}
})
.map(|res| match res {
Ok(v) => v,
Err(e) => e,
})
.collect::<Vec<String>>();
println!("Not evens: {:?}", res);
}