File: 06-no-auto-send-sync-with-non-send-sync-ffi-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 (51 lines) | stat: -rw-r--r-- 1,218 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
glib::wrapper! {
    #[doc(alias = "GInitiallyUnowned")]
    pub struct InitiallyUnowned(Object<glib::gobject_ffi::GInitiallyUnowned, glib::gobject_ffi::GInitiallyUnownedClass>);

    match fn {
        type_ => || glib::gobject_ffi::g_initially_unowned_get_type(),
    }
}

pub trait InitiallyUnownedImpl: glib::subclass::prelude::ObjectImpl {}

unsafe impl<T: InitiallyUnownedImpl> glib::subclass::prelude::IsSubclassable<T>
    for InitiallyUnowned
{
}

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::InitiallyUnowned;
    }

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

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

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

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

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