#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, Hash)]
struct ContentItem {
id: i32,
name: String,
}
let myitems = vec![
ContentItem {
id: 0,
name: "Test item 0".to_string(),
},
ContentItem {
id: 1,
name: "Test item 1".to_string(),
},
ContentItem {
id: 2,
name: "Test item 2".to_string(),
},
];
let values: ContentItem = myitems.into_iter().enumerate().collect();
#How do i Fix `value of type cannot be built from Iterator` Error?
3 messages · Page 1 of 1 (latest)
^^^^^^^^^
error[E0277]: a value of type `ContentItem` cannot be built from an iterator over elements of type `(usize, ContentItem)`
--> src/main.rs:320:31
|
320 | let values: ContentItem = myitems.into_iter().enumerate().collect();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ------- required by a bound introduced by this call
| |
| value of type `ContentItem` cannot be built from `std::iter::Iterator<Item=(usize, ContentItem)>`
|
= help: the trait `FromIterator<(usize, ContentItem)>` is not implemented for `ContentItem`
note: required by a bound in `collect`
-->.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/iter/traits/iterator.rs:1832:19
|
1832 | fn collect<B: FromIterator<Self::Item>>(self) -> B
| ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `collect`
For more information about this error, try `rustc --explain E0277`.
You probably want the type to be something like Vec<(usize, ContentItem)>