Hi everyone !
I want to optimize my app and according to the optimization process I want to make my Modal to accept &[ &[ (&str, &str) ] ]
:
type NamedValue<'a> = (&'a str, &'a str);
type NamedValueList<'a> = &'a [NamedValue<'a>];
#[derive(Default, Clone, Copy)]
pub struct Modal<'a> {
title: &'a str,
items: &'a [NamedValueList<'a>],
}
impl<'a> Modal<'a> {
pub fn new(title: &'a str, items: &'a [NamedValueList<'a>]) -> Self {
Self {
title,
items,
}
}
}
but when I pass some data into the modal:
HandlerOutput::TransferCharactersList(characters) => {
let items = characters.iter().map(|c| {
[
("Guid:", c.guid.to_string().as_str()),
("name:", c.name.as_str())
]
}).collect();
*modal.lock().await = Modal::new(
"SELECT CHARACTER",
items,
)
}
I got such error:
error[E0277]: a value of type `&[&[(&str, &str)]]` cannot be built from an iterator over elements of type `[(&str, &str); 2]`
--> src/features/ui2/mod.rs:73:40
|
73 | ... }).collect();
| ^^^^^^^ value of type `&[&[(&str, &str)]]` cannot be built from `std::iter::Iterator<Item=[(&str, &str); 2]>`
|
= help: the trait `FromIterator<[(&str, &str); 2]>` is not implemented for `&[&[(&str, &str)]]`
note: the method call chain might not have had the expected associated types
--> src/features/ui2/mod.rs:68:87
|
68 | ... let items: &[&[(&str, &str)]] = characters.iter().map(|c| {
| _______________________________________________________----------_------_^
| | | |
| | | `Iterator::Item` is `&Object` here
| | this expression has type `Vec<Object>`
69 | | ... [
70 | | ... ("Guid:", c.guid.to_string().as_str()),
71 | | ... ("name:", c.name.as_str())
72 | | ... ]
73 | | ... }).collect();
| |________________________^ `Iterator::Item` changed to `[(&str, &str); 2]` here
note: required by a bound in `std::iter::Iterator::collect`
Could somebody explain, how can I fix this issue ?