| 1 |
use glib::prelude::*; |
| 2 |
use glib::subclass::prelude::*; |
| 3 |
use glib_macros::Properties; |
| 4 |
use std::cell::RefCell; |
| 5 |
pub mod imp { |
| 6 |
use super::*; |
| 7 |
|
| 8 |
#[derive(Properties, Default)] |
| 9 |
#[properties(wrapper_type = super::Foo)] |
| 10 |
pub struct Foo { |
| 11 |
#[property(get, set)] |
| 12 |
match_info: RefCell<Option<glib::MatchInfo<'static>>>, |
| 13 |
} |
| 14 |
|
| 15 |
#[glib::derived_properties] |
| 16 |
impl ObjectImpl for Foo {} |
| 17 |
|
| 18 |
#[glib::object_subclass] |
| 19 |
impl ObjectSubclass for Foo { |
| 20 |
const NAME: &'static str = "MyFoo"; |
| 21 |
type Type = super::Foo; |
| 22 |
} |
| 23 |
} |
| 24 |
|
| 25 |
glib::wrapper! { |
| 26 |
pub struct Foo(ObjectSubclass<imp::Foo>); |
| 27 |
} |
| 28 |
|
| 29 |
fn main() { |
| 30 |
let myfoo: Foo = glib::object::Object::new(); |
| 31 |
|
| 32 |
let r = glib::Regex::new( |
| 33 |
"hello", |
| 34 |
glib::RegexCompileFlags::DEFAULT, |
| 35 |
glib::RegexMatchFlags::DEFAULT, |
| 36 |
) |
| 37 |
.unwrap() |
| 38 |
.unwrap(); |
| 39 |
|
| 40 |
let s = glib::GStr::from_str_until_nul("hello\0").unwrap(); |
| 41 |
let match_info = r |
| 42 |
.match_(s, glib::RegexMatchFlags::DEFAULT) |
| 43 |
.expect("should match"); |
| 44 |
|
| 45 |
myfoo.set_match_info(match_info); |
| 46 |
|
| 47 |
let match_info: glib::MatchInfo<'_> = myfoo.match_info().unwrap(); |
| 48 |
assert_eq!(match_info.fetch_all(), vec!["hello"]); |
| 49 |
} |