I’m trying to get from this:
let a: Option<&str> = Some("foo");
let b: Option<String> = a.map(|s| s.to_string());
to a tuple form:
let c: (Option<&str>, Option<&str>) = (Some("bar"), Some("baz"));
let d: (Option<String>, Option<String>) = c.map(|s| (s.0.to_string(), s.1.to_string()));
7 | let d: (Option<String>, Option<String>) = c.map(|s| (s.0.to_string(), s.1.to_string()));
| ^^^ `(Option<&str>, Option<&str>)` is not an iterator
|
= note: the following trait bounds were not satisfied:
`(Option<&str>, Option<&str>): Iterator`
which is required by `&mut (Option<&str>, Option<&str>): Iterator
How can I convert the tuple of optional string slices to a tuple of optional strings using rust 1.61 or newer?
>Solution :
Just do as you did when you had two variables:
let c = (Some("bar"), Some("baz"));
let d = (c.0.map(|s| s.to_string()), c.1.map(|s| s.to_string()));