如何从元组转换(option<& str> option< st str; str>)tuple(option< string> string> option&lt string>)?
我正在尝试从中获取:
let a: Option<&str> = Some("foo");
let b: Option<String> = a.map(|s| s.to_string());
转到元组形式:
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
如何使用Rust 1.61
或更新的元组转换为可选字符串的元组?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
就像您有两个变量时那样做:
Just do as you did when you had two variables: