rust
1const TABLE1: [(&str, &str); 6] = [ 2 ("a", "あ"), ("i", "い"), ("u", "う"), ("e", "え"), ("o", "お"), 3 ("n", "ん") 4];
のような配列があったとき、
rust
1vec![ 2 ("あ", "a"), ("い", "i"), ("う", "u"), ("え", "e"), ("お", "o"), 3 ("ん", "n") 4]
と等価なVec<(&str, &str)>
へ変換したいです。
rust
1TABLE1.iter().map(|(s1, s2)| (s2, s1)).cloned().collect::<Vec<(&str, &str)>>()
のようにすれば行けないかと思いましたが、これでは
error[E0271]: type mismatch resolving `<std::iter::Map<std::slice::Iter<'_, (&str, &str)>, [closure@src\cvt\jis_x_4063_2000.rs:94:27: 94:46]> as std::iter::Iterator>::Item == &_` --> src\cvt\jis_x_4063_2000.rs:94:48 | 94 | TABLE1.iter().map(|(s1, s2)| (s2, s1)).cloned().collect::<Vec<(&str, &str)>>(), | ^^^^^^ expected tuple, found reference | = note: expected type `(&&str, &&str)` found type `&_` error[E0599]: no method named `collect` found for type `std::iter::Cloned<std::iter::Map<std::slice::Iter<'_, (&str, &str)>, [closure@src\cvt\jis_x_4063_2000.rs:94:27: 94:46]>>` in the current scope --> src\cvt\jis_x_4063_2000.rs:94:57 | 94 | TABLE1.iter().map(|(s1, s2)| (s2, s1)).cloned().collect::<Vec<(&str, &str)>>(), | ^^^^^^^ | = note: the method `collect` exists but the following trait bounds were not satisfied: `std::iter::Cloned<std::iter::Map<std::slice::Iter<'_, (&str, &str)>, [closure@src\cvt\jis_x_4063_2000.rs:94:27: 94:46]>> : std::iter::Iterator` `&mut std::iter::Cloned<std::iter::Map<std::slice::Iter<'_, (&str, &str)>, [closure@src\cvt\jis_x_4063_2000.rs:94:27: 94:46]>> : std::iter::Iterator` error: aborting due to 2 previous errors
のようにエラーになってしまいます。というかexpected tuple, found reference
ってどういうことなんでしょうか?

回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。