i have a Vec, where i need to match the value of the string to specific other strings, in order to match each and every one of them, i decided to use Vec.iter().map(...) to solve this issue (and also since i want to use rayon in that project). here is some example code to explain what i mean:
use thiserror::Error; // 1.0.48
#[derive(Error)]
#[derive(Debug, Clone, PartialOrd, PartialEq)]
pub enum SomeError {
#[error("some error data {0}")]
ExampleError(String),
}
fn main(){
let Vector = Vec::new();
for _ in 0..100{Vector.push("foo");}
let Vector = Vector.iter().map(|value|{
match value{
&"foo" => "bar",
&"bar" => "foo",
_ => return SomeError::ExampleError(String::from("unknown value")),
}
}
);
}
if you tried this code in the rust playground, you'd see it returns
Compiling playground v0.0.1 (/playground)
error[E0308]: mismatched types
--> src/main.rs:17:9
|
17 | / match value{
18 | | &"foo" => "bar",
19 | | &"bar" => "foo",
20 | | _ => return SomeError::ExampleError(String::from("unknown value")),
21 | | }
| |_________^ expected `SomeError`, found `&str`
|
note: return type inferred to be `SomeError` here
--> src/main.rs:20:25
|
20 | _ => return SomeError::ExampleError(String::from("unknown value")),
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
For more information about this error, try `rustc --explain E0308`.
error: could not compile `playground` (bin "playground") due to previous error
i don't want to return the value in _ into the match function, i want to return that value to the actual function, so, how can i return a value from the map() function directly into the function using it, not to the variable?