我正在尝试创建一个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,所以错误并不是非常精确。
String
而不是str
。您可以使用"example".to_string()
将str
转换为String
。 - Wesley Wiserlist_model.insert_with_values(None, &[0], &[&("S".to_value()) as &ToValue]);
。 - Geob-o-matic