Skip to content

Commit a572418

Browse files
committed
add glib::gobject:{TypePlugin,TypeModule,InterfaceInfo,TypeInfo,EnumValue,FlagsValue,TypeValueTable,TypeFlags}
Signed-off-by: fbrouille <[email protected]>
1 parent 8986eb9 commit a572418

12 files changed

+377
-4
lines changed

glib/Gir_GObject.toml

+8
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ girs_directories = ["../gir-files"]
1414
generate = [
1515
"GObject.BindingFlags",
1616
"GObject.SignalFlags",
17+
"GObject.TypeFlags",
18+
"GObject.TypePlugin",
19+
"GObject.TypeModule",
1720
]
1821

1922
ignore = [
@@ -23,6 +26,9 @@ manual = [
2326
"GLib.Quark",
2427
"GObject.Object",
2528
"GObject.Value",
29+
"GObject.EnumValue",
30+
"GObject.FlagsValue",
31+
"GObject.TypeValueTable",
2632
"GObject.ParamFlags",
2733
"GObject.ParamSpec",
2834
"GObject.ParamSpecChar",
@@ -48,6 +54,8 @@ manual = [
4854
"GObject.ParamSpecOverride",
4955
"GObject.ParamSpecGType",
5056
"GObject.ParamSpecVariant",
57+
"GObject.InterfaceInfo",
58+
"GObject.TypeInfo",
5159
]
5260

5361
[[object]]

glib/src/enums.rs

+21-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Take a look at the license at the top of the repository in the LICENSE file.
22

3-
use std::{cmp, ffi::CStr, fmt, ptr};
3+
use std::{cmp, ffi::CStr, fmt, marker::PhantomData, ptr};
44

55
use crate::{
66
translate::*,
@@ -300,6 +300,16 @@ unsafe impl<'a, 'b> FromValue<'a> for &'b EnumValue {
300300
}
301301
}
302302

303+
#[doc(hidden)]
304+
impl<'a> ToGlibPtr<'a, *const gobject_ffi::GEnumValue> for EnumValue {
305+
type Storage = PhantomData<&'a Self>;
306+
307+
#[inline]
308+
fn to_glib_none(&'a self) -> Stash<'a, *const gobject_ffi::GEnumValue, Self> {
309+
Stash(&self.0 as *const gobject_ffi::GEnumValue, PhantomData)
310+
}
311+
}
312+
303313
pub struct EnumTypeChecker();
304314
unsafe impl ValueTypeChecker for EnumTypeChecker {
305315
type Error = InvalidEnumError;
@@ -806,6 +816,16 @@ impl PartialEq for FlagsValue {
806816

807817
impl Eq for FlagsValue {}
808818

819+
#[doc(hidden)]
820+
impl<'a> ToGlibPtr<'a, *const gobject_ffi::GFlagsValue> for FlagsValue {
821+
type Storage = PhantomData<&'a Self>;
822+
823+
#[inline]
824+
fn to_glib_none(&'a self) -> Stash<'a, *const gobject_ffi::GFlagsValue, Self> {
825+
Stash(&self.0 as *const gobject_ffi::GFlagsValue, PhantomData)
826+
}
827+
}
828+
809829
// rustdoc-stripper-ignore-next
810830
/// Builder for conveniently setting/unsetting flags and returning a `Value`.
811831
///

glib/src/gobject/auto/flags.rs

+41
Original file line numberDiff line numberDiff line change
@@ -149,3 +149,44 @@ impl FromGlib<gobject_ffi::GSignalFlags> for SignalFlags {
149149
Self::from_bits_truncate(value)
150150
}
151151
}
152+
153+
bitflags! {
154+
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
155+
#[doc(alias = "GTypeFlags")]
156+
pub struct TypeFlags: u32 {
157+
#[doc(alias = "G_TYPE_FLAG_NONE")]
158+
const NONE = gobject_ffi::G_TYPE_FLAG_NONE as _;
159+
#[doc(alias = "G_TYPE_FLAG_ABSTRACT")]
160+
const ABSTRACT = gobject_ffi::G_TYPE_FLAG_ABSTRACT as _;
161+
#[doc(alias = "G_TYPE_FLAG_VALUE_ABSTRACT")]
162+
const VALUE_ABSTRACT = gobject_ffi::G_TYPE_FLAG_VALUE_ABSTRACT as _;
163+
#[doc(alias = "G_TYPE_FLAG_FINAL")]
164+
const FINAL = gobject_ffi::G_TYPE_FLAG_FINAL as _;
165+
#[doc(alias = "G_TYPE_FLAG_DEPRECATED")]
166+
const DEPRECATED = gobject_ffi::G_TYPE_FLAG_DEPRECATED as _;
167+
}
168+
}
169+
170+
impl fmt::Display for TypeFlags {
171+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
172+
<Self as fmt::Debug>::fmt(self, f)
173+
}
174+
}
175+
176+
#[doc(hidden)]
177+
impl IntoGlib for TypeFlags {
178+
type GlibType = gobject_ffi::GTypeFlags;
179+
180+
#[inline]
181+
fn into_glib(self) -> gobject_ffi::GTypeFlags {
182+
self.bits()
183+
}
184+
}
185+
186+
#[doc(hidden)]
187+
impl FromGlib<gobject_ffi::GTypeFlags> for TypeFlags {
188+
#[inline]
189+
unsafe fn from_glib(value: gobject_ffi::GTypeFlags) -> Self {
190+
Self::from_bits_truncate(value)
191+
}
192+
}

glib/src/gobject/auto/mod.rs

+13
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,19 @@ mod signal_group;
1919
#[cfg_attr(docsrs, doc(cfg(feature = "v2_74")))]
2020
pub use self::signal_group::SignalGroup;
2121

22+
mod type_module;
23+
pub use self::type_module::TypeModule;
24+
25+
mod type_plugin;
26+
pub use self::type_plugin::TypePlugin;
27+
2228
mod flags;
2329
pub use self::flags::BindingFlags;
2430
pub use self::flags::SignalFlags;
31+
pub use self::flags::TypeFlags;
32+
33+
#[doc(hidden)]
34+
pub mod traits {
35+
pub use super::type_module::TypeModuleExt;
36+
pub use super::type_plugin::TypePluginExt;
37+
}

glib/src/gobject/auto/type_module.rs

+121
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
// This file was generated by gir (https://github.com/gtk-rs/gir)
2+
// from gir-files (https://github.com/gtk-rs/gir-files)
3+
// DO NOT EDIT
4+
5+
use crate::{
6+
prelude::*, translate::*, EnumValue, FlagsValue, InterfaceInfo, TypeFlags, TypeInfo, TypePlugin,
7+
};
8+
use std::fmt;
9+
10+
crate::wrapper! {
11+
#[doc(alias = "GTypeModule")]
12+
pub struct TypeModule(Object<gobject_ffi::GTypeModule, gobject_ffi::GTypeModuleClass>) @implements TypePlugin;
13+
14+
match fn {
15+
type_ => || gobject_ffi::g_type_module_get_type(),
16+
}
17+
}
18+
19+
impl TypeModule {
20+
pub const NONE: Option<&'static TypeModule> = None;
21+
}
22+
23+
mod sealed {
24+
pub trait Sealed {}
25+
impl<T: super::IsA<super::TypeModule>> Sealed for T {}
26+
}
27+
28+
pub trait TypeModuleExt: IsA<TypeModule> + sealed::Sealed + 'static {
29+
#[doc(alias = "g_type_module_add_interface")]
30+
fn add_interface(
31+
&self,
32+
instance_type: crate::types::Type,
33+
interface_type: crate::types::Type,
34+
interface_info: &InterfaceInfo,
35+
) {
36+
unsafe {
37+
gobject_ffi::g_type_module_add_interface(
38+
self.as_ref().to_glib_none().0,
39+
instance_type.into_glib(),
40+
interface_type.into_glib(),
41+
interface_info.to_glib_none().0,
42+
);
43+
}
44+
}
45+
46+
#[doc(alias = "g_type_module_register_enum")]
47+
fn register_enum(&self, name: &str, const_static_values: &EnumValue) -> crate::types::Type {
48+
unsafe {
49+
from_glib(gobject_ffi::g_type_module_register_enum(
50+
self.as_ref().to_glib_none().0,
51+
name.to_glib_none().0,
52+
const_static_values.to_glib_none().0,
53+
))
54+
}
55+
}
56+
57+
#[doc(alias = "g_type_module_register_flags")]
58+
fn register_flags(&self, name: &str, const_static_values: &FlagsValue) -> crate::types::Type {
59+
unsafe {
60+
from_glib(gobject_ffi::g_type_module_register_flags(
61+
self.as_ref().to_glib_none().0,
62+
name.to_glib_none().0,
63+
const_static_values.to_glib_none().0,
64+
))
65+
}
66+
}
67+
68+
#[doc(alias = "g_type_module_register_type")]
69+
fn register_type(
70+
&self,
71+
parent_type: crate::types::Type,
72+
type_name: &str,
73+
type_info: &TypeInfo,
74+
flags: TypeFlags,
75+
) -> crate::types::Type {
76+
unsafe {
77+
from_glib(gobject_ffi::g_type_module_register_type(
78+
self.as_ref().to_glib_none().0,
79+
parent_type.into_glib(),
80+
type_name.to_glib_none().0,
81+
type_info.to_glib_none().0,
82+
flags.into_glib(),
83+
))
84+
}
85+
}
86+
87+
#[doc(alias = "g_type_module_set_name")]
88+
fn set_name(&self, name: &str) {
89+
unsafe {
90+
gobject_ffi::g_type_module_set_name(
91+
self.as_ref().to_glib_none().0,
92+
name.to_glib_none().0,
93+
);
94+
}
95+
}
96+
97+
#[doc(alias = "g_type_module_unuse")]
98+
fn unuse(&self) {
99+
unsafe {
100+
gobject_ffi::g_type_module_unuse(self.as_ref().to_glib_none().0);
101+
}
102+
}
103+
104+
#[doc(alias = "g_type_module_use")]
105+
#[doc(alias = "use")]
106+
fn use_(&self) -> bool {
107+
unsafe {
108+
from_glib(gobject_ffi::g_type_module_use(
109+
self.as_ref().to_glib_none().0,
110+
))
111+
}
112+
}
113+
}
114+
115+
impl<O: IsA<TypeModule>> TypeModuleExt for O {}
116+
117+
impl fmt::Display for TypeModule {
118+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
119+
f.write_str("TypeModule")
120+
}
121+
}

glib/src/gobject/auto/type_plugin.rs

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
// This file was generated by gir (https://github.com/gtk-rs/gir)
2+
// from gir-files (https://github.com/gtk-rs/gir-files)
3+
// DO NOT EDIT
4+
5+
use crate::{prelude::*, translate::*, InterfaceInfo, TypeInfo, TypeValueTable};
6+
use std::fmt;
7+
8+
crate::wrapper! {
9+
#[doc(alias = "GTypePlugin")]
10+
pub struct TypePlugin(Interface<gobject_ffi::GTypePlugin, gobject_ffi::GTypePluginClass>);
11+
12+
match fn {
13+
type_ => || gobject_ffi::g_type_plugin_get_type(),
14+
}
15+
}
16+
17+
impl TypePlugin {
18+
pub const NONE: Option<&'static TypePlugin> = None;
19+
}
20+
21+
mod sealed {
22+
pub trait Sealed {}
23+
impl<T: super::IsA<super::TypePlugin>> Sealed for T {}
24+
}
25+
26+
pub trait TypePluginExt: IsA<TypePlugin> + sealed::Sealed + 'static {
27+
#[doc(alias = "g_type_plugin_complete_interface_info")]
28+
fn complete_interface_info(
29+
&self,
30+
instance_type: crate::types::Type,
31+
interface_type: crate::types::Type,
32+
info: &mut InterfaceInfo,
33+
) {
34+
unsafe {
35+
gobject_ffi::g_type_plugin_complete_interface_info(
36+
self.as_ref().to_glib_none().0,
37+
instance_type.into_glib(),
38+
interface_type.into_glib(),
39+
info.to_glib_none_mut().0,
40+
);
41+
}
42+
}
43+
44+
#[doc(alias = "g_type_plugin_complete_type_info")]
45+
fn complete_type_info(
46+
&self,
47+
g_type: crate::types::Type,
48+
info: &mut TypeInfo,
49+
value_table: &mut TypeValueTable,
50+
) {
51+
unsafe {
52+
gobject_ffi::g_type_plugin_complete_type_info(
53+
self.as_ref().to_glib_none().0,
54+
g_type.into_glib(),
55+
info.to_glib_none_mut().0,
56+
value_table.to_glib_none_mut().0,
57+
);
58+
}
59+
}
60+
61+
#[doc(alias = "g_type_plugin_unuse")]
62+
fn unuse(&self) {
63+
unsafe {
64+
gobject_ffi::g_type_plugin_unuse(self.as_ref().to_glib_none().0);
65+
}
66+
}
67+
68+
#[doc(alias = "g_type_plugin_use")]
69+
#[doc(alias = "use")]
70+
fn use_(&self) {
71+
unsafe {
72+
gobject_ffi::g_type_plugin_use(self.as_ref().to_glib_none().0);
73+
}
74+
}
75+
}
76+
77+
impl<O: IsA<TypePlugin>> TypePluginExt for O {}
78+
79+
impl fmt::Display for TypePlugin {
80+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
81+
f.write_str("TypePlugin")
82+
}
83+
}

glib/src/gobject/interface_info.rs

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Take a look at the license at the top of the repository in the LICENSE file.
2+
3+
wrapper! {
4+
#[derive(Debug)]
5+
#[doc(alias = "GInterfaceInfo")]
6+
pub struct InterfaceInfo(BoxedInline<gobject_ffi::GInterfaceInfo>);
7+
8+
match fn {
9+
copy => |ptr| {
10+
let copy = ffi::g_malloc(std::mem::size_of::<gobject_ffi::GInterfaceInfo>()) as *mut gobject_ffi::GInterfaceInfo;
11+
std::ptr::copy_nonoverlapping(ptr, copy, 1);
12+
copy
13+
},
14+
free => |ptr| ffi::g_free(ptr as *mut _),
15+
}
16+
}

glib/src/gobject/mod.rs

+9
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,12 @@ pub use binding_group::BindingGroupBuilder;
2020

2121
pub use self::{auto::*, flags::*};
2222
//pub use self::auto::functions::*;
23+
24+
mod type_value_table;
25+
pub use type_value_table::TypeValueTable;
26+
27+
mod type_info;
28+
pub use type_info::TypeInfo;
29+
30+
mod interface_info;
31+
pub use interface_info::InterfaceInfo;

glib/src/gobject/type_info.rs

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Take a look at the license at the top of the repository in the LICENSE file.
2+
3+
wrapper! {
4+
#[derive(Debug)]
5+
#[doc(alias = "GTypeInfo")]
6+
pub struct TypeInfo(BoxedInline<gobject_ffi::GTypeInfo>);
7+
8+
match fn {
9+
copy => |ptr| {
10+
let copy = ffi::g_malloc(std::mem::size_of::<gobject_ffi::GTypeInfo>()) as *mut gobject_ffi::GTypeInfo;
11+
std::ptr::copy_nonoverlapping(ptr, copy, 1);
12+
copy
13+
},
14+
free => |ptr| ffi::g_free(ptr as *mut _),
15+
}
16+
}

0 commit comments

Comments
 (0)