File: 01-not-dangling.rs

package info (click to toggle)
rust-glib 0.20.9-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,308 kB
  • sloc: makefile: 18
file content (29 lines) | stat: -rw-r--r-- 812 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
fn main() {
    let r = glib::Regex::new(
        "hello",
        glib::RegexCompileFlags::DEFAULT,
        glib::RegexMatchFlags::DEFAULT,
    )
    .unwrap()
    .unwrap();
    // implicit drop
    {
        let s = glib::GString::from("hello");
        let match_info = r
            .match_(s.as_gstr(), glib::RegexMatchFlags::DEFAULT)
            .expect("should match");
        assert_eq!(match_info.fetch_all(), vec!["hello"]);
        // match_info is dropped
        // s is dropped
    }
    // explicit drop
    {
        let s = glib::GString::from("hello");
        let match_info = r
            .match_(s.as_gstr(), glib::RegexMatchFlags::DEFAULT)
            .expect("should match");
        assert_eq!(match_info.fetch_all(), vec!["hello"]);
        drop(match_info);
        drop(s);
    }
}