gtkliststoreitem

Build Latest version Documentation License

Automatic gtk::ListStore struct derive for Rust.

Usage

In order to use this crate, you have to add the following dependencies into your project's Cargo.toml file:

toml [dependencies] gtk_liststore_item = "1.0.1"

Example

After the crate is installed, you can enjoy the ListStoreItem derive!

```rust use gtk::prelude::*;

use gladis::Gladis; use gtkliststoreitem::ListStoreItem;

const GLADE_SRC: &str = r#" "#;

[derive(Gladis)]

struct Glade { list_store: gtk::ListStore, }

[derive(ListStoreItem)]

struct Item { name: String, value: u32, }

fn main() { gtk::init().unwrap();

let mut glade = Glade::from_string(GLADE_SRC).unwrap();

let item = Item { name: "foobar".into(), value: 42 };
let iter = item.insert_into_liststore(&mut glade.list_store);

let retrieved_item = Item::from_liststore_iter(&glade.list_store, &iter).unwrap();
assert_eq!("foobar", retrieved_item.name);
assert_eq!(42, retrieved_item.value);

} ```

Without this crate, you would have to manually serialize each of the entries in your struct with their type and position:

```rust fn getitem(liststore: &gtk::ListStore, iter: &gtk::TreeIter) -> Item { Some(Item { name: liststore.value(&iter, 0).get::().ok()?, value: list_store.value(&iter, 1).get::().ok()?, }) }

fn insertitem(item: &Item, liststore: &mut gtk::ListStore) -> gtk::TreeIter { liststore.insertwith_values( None, &[ (0, &self.name), (1, &self.value) ] ) } ```

This can become pretty boring, hence this crate to ease the process.

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this project by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.