Как преобразовать строку Rust в gtk::type::String?
Я пытаюсь создать ComboBox
, особенно модель для него:
let type_in_col = &[gtk::Type::String];
let list_model = ListStore::new(type_in_col);
list_model.insert_with_values(None, &[0], &[""]);
list_model.insert_with_values(None, &[0], &["h"]);
list_model.insert_with_values(None, &[0], &["H"]);
list_model.insert_with_values(None, &[0], &["W"]);
list_model.insert_with_values(None, &[0], &["S"]);
Этот кусок кода дал мне эту ошибку:
error[E0277]: the trait bound `str: std::marker::Sized` is not satisfied
--> src\widgets\daywidget.rs:36:1
|
36 | #[widget]
| ^^^^^^^^^ `str` does not have a constant size known at compile-time
|
= help: the trait `std::marker::Sized` is not implemented for `str`
= note: required for the cast to the object type `gtk::ToValue`
(ошибка не очень точная, потому что я использую Relm)
1 ответ
Решение
Вместо этого вы хотите использовать следующее:
let type_in_col = &[gtk::Type::String];
let list_model = ListStore::new(type_in_col);
list_model.insert_with_values(None, &[0], &[&""]);
list_model.insert_with_values(None, &[0], &[&"h"]);
list_model.insert_with_values(None, &[0], &[&"H"]);
list_model.insert_with_values(None, &[0], &[&"W"]);
list_model.insert_with_values(None, &[0], &[&"S"]);
поскольку SetValue
реализован для &T where T: ?Sized
,
Вы не можете разыграть из &str
в &ToValue
: смотрите здесь по причинам.