3

I'm trying to create a ComboBox, especially the model for it:

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"]);

This piece of code gave me this error:

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`

(the error is not very precise because I'm using Relm)

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
Geob-o-matic
  • 5,940
  • 4
  • 35
  • 41

1 Answers1

2

You want to use the following, instead:

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"]);

since SetValue is implemented for &T where T: ?Sized.

You cannot cast from &str to &ToValue: see here for the reasons.

antoyo
  • 11,097
  • 7
  • 51
  • 82
  • `this function takes 4 parameters but 3 parameters were supplied (expected 4 parameters) [E0061] [4 times]` at the `None`s – Zelphir Kaltstahl Oct 05 '17 at 17:41
  • 1
    @Zelphir: You're probably using a `TreeStore` instead of a `ListStore`. The former also needs a parent to be specified, which can be `None`. – antoyo Oct 06 '17 at 00:36