【发布时间】:2017-06-02 06:01:02
【问题描述】:
我正在尝试创建一个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。 -
我设法找到了一个例子,它正在做
list_model.insert_with_values(None, &[0], &[&("S".to_value()) as &ToValue]); -
您应该将其添加为答案!