File: 04-auto-send-sync-with-send-sync-parent.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 (69 lines) | stat: -rw-r--r-- 1,489 bytes parent folder | download | duplicates (4)
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
mod imp_parent {
    use glib::subclass::prelude::*;

    #[derive(Default)]
    pub struct TestParent {
        s: String,
    }

    #[glib::object_subclass]
    impl ObjectSubclass for TestParent {
        const NAME: &'static str = "TestParent";
        type Type = super::TestParent;
    }

    impl ObjectImpl for TestParent {}
}

glib::wrapper! {
    pub struct TestParent(ObjectSubclass<imp_parent::TestParent>);
}

pub trait TestParentImpl: glib::subclass::prelude::ObjectImpl + Send + Sync {}

unsafe impl<T: TestParentImpl> glib::subclass::prelude::IsSubclassable<T> for TestParent {}

impl Default for TestParent {
    fn default() -> Self {
        glib::Object::new()
    }
}

mod imp_object {
    use glib::subclass::prelude::*;

    #[derive(Default)]
    pub struct TestObject {
        s: String,
    }

    #[glib::object_subclass]
    impl ObjectSubclass for TestObject {
        const NAME: &'static str = "TestObject";
        type Type = super::TestObject;
        type ParentType = super::TestParent;
    }

    impl ObjectImpl for TestObject {}
    impl super::TestParentImpl for TestObject {}
}

glib::wrapper! {
    pub struct TestObject(ObjectSubclass<imp_object::TestObject>) @extends TestParent;
}

impl Default for TestObject {
    fn default() -> Self {
        glib::Object::new()
    }
}

fn main() {
    fn check<T: Send + Sync>(_obj: &T) {}

    let obj = TestParent::default();
    check(&obj);

    let obj = TestObject::default();
    check(&obj);
}