Debian Codegraph @

tests/enum_dynamic.rs

raw symbols SCIP
1 // Take a look at the license at the top of the repository in the LICENSE file.
2
3 use glibrust-analyzer cargo glib 0.22.5 crate/::{preluderust-analyzer cargo glib 0.22.5 prelude/::*, subclassrust-analyzer cargo glib 0.22.5 subclass/::preluderust-analyzer cargo glib 0.22.5 subclass/prelude/::*};
4
5 mod modulerust-analyzer cargo glib-macros 0.22.6 module/ {
6 use superrust-analyzer cargo glib-macros 0.22.6 crate/::*;
7
8 mod imprust-analyzer cargo glib-macros 0.22.6 module/imp/ {
9 use superrust-analyzer cargo glib-macros 0.22.6 module/::*;
10
11 // impl for a type module (must extend `glib::TypeModule` and must implement `glib::TypePlugin`).
12 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default:)]
13 pub struct MyModulerust-analyzer cargo glib-macros 0.22.6 module/imp/MyModule#;
14
15 #[glibrust-analyzer cargo glib 0.22.5 crate/::object_subclassrust-analyzer cargo glib-macros 0.22.2 object_subclass:]
16 impl ObjectSubclassrust-analyzer cargo glib 0.22.5 subclass/types/ObjectSubclass# for MyModulerust-analyzer cargo glib-macros 0.22.6 module/imp/MyModule# {
17 const NAMErust-analyzer cargo glib-macros 0.22.6 module/imp/impl#[MyModule][ObjectSubclass]NAME.: &'static str = "MyModule";
18 type Typerust-analyzer cargo glib-macros 0.22.6 module/imp/impl#[MyModule][ObjectSubclass]Type# = superrust-analyzer cargo glib-macros 0.22.6 module/::MyModulerust-analyzer cargo glib-macros 0.22.6 module/MyModule#;
19 type ParentTyperust-analyzer cargo glib-macros 0.22.6 module/imp/impl#[MyModule][ObjectSubclass]ParentType# = glibrust-analyzer cargo glib 0.22.5 crate/::TypeModulerust-analyzer cargo glib 0.22.5 gobject/type_module/TypeModule#;
20 type Interfacesrust-analyzer cargo glib-macros 0.22.6 module/imp/impl#[MyModule][ObjectSubclass]Interfaces# = (glibrust-analyzer cargo glib 0.22.5 crate/::TypePluginrust-analyzer cargo glib 0.22.5 gobject/type_plugin/TypePlugin#,);
21 }
22
23 impl ObjectImplrust-analyzer cargo glib 0.22.5 subclass/object/ObjectImpl# for MyModulerust-analyzer cargo glib-macros 0.22.6 module/imp/MyModule# {}
24
25 impl TypePluginImplrust-analyzer cargo glib 0.22.5 subclass/type_plugin/TypePluginImpl# for MyModulerust-analyzer cargo glib-macros 0.22.6 module/imp/MyModule# {}
26
27 impl TypeModuleImplrust-analyzer cargo glib 0.22.5 subclass/type_module/TypeModuleImpl# for MyModulerust-analyzer cargo glib-macros 0.22.6 module/imp/MyModule# {
28 fn loadrust-analyzer cargo glib-macros 0.22.6 module/imp/impl#[MyModule][TypeModuleImpl]load().(&self) -> bool {
29 // registers enums as dynamic types.
30 let my_module = self.objrust-analyzer cargo glib 0.22.5 subclass/types/impl#[T][ObjectSubclassExt]obj().();
31 let type_module: &glibrust-analyzer cargo glib 0.22.5 crate/::TypeModulerust-analyzer cargo glib 0.22.5 gobject/type_module/TypeModule# = my_module.upcast_refrust-analyzer cargo glib 0.22.5 object/Cast#upcast_ref().();
32 superrust-analyzer cargo glib-macros 0.22.6 module/::MyModuleEnumrust-analyzer cargo glib-macros 0.22.6 module/MyModuleEnum#::on_implementation_loadrust-analyzer cargo glib-macros 0.22.6 module/impl#[MyModuleEnum]on_implementation_load().(type_module)
33 && superrust-analyzer cargo glib-macros 0.22.6 module/::MyModuleEnumLazyrust-analyzer cargo glib-macros 0.22.6 module/MyModuleEnumLazy#::on_implementation_loadrust-analyzer cargo glib-macros 0.22.6 module/impl#[MyModuleEnumLazy]on_implementation_load().(type_module)
34 }
35
36 fn unloadrust-analyzer cargo glib-macros 0.22.6 module/imp/impl#[MyModule][TypeModuleImpl]unload().(&self) {
37 // marks the enums as unregistered.
38 let my_module = self.objrust-analyzer cargo glib 0.22.5 subclass/types/impl#[T][ObjectSubclassExt]obj().();
39 let type_module: &glibrust-analyzer cargo glib 0.22.5 crate/::TypeModulerust-analyzer cargo glib 0.22.5 gobject/type_module/TypeModule# = my_module.upcast_refrust-analyzer cargo glib 0.22.5 object/Cast#upcast_ref().();
40 superrust-analyzer cargo glib-macros 0.22.6 module/::MyModuleEnumLazyrust-analyzer cargo glib-macros 0.22.6 module/MyModuleEnumLazy#::on_implementation_unloadrust-analyzer cargo glib-macros 0.22.6 module/impl#[MyModuleEnumLazy]on_implementation_unload().(type_module);
41 superrust-analyzer cargo glib-macros 0.22.6 module/::MyModuleEnumrust-analyzer cargo glib-macros 0.22.6 module/MyModuleEnum#::on_implementation_unloadrust-analyzer cargo glib-macros 0.22.6 module/impl#[MyModuleEnum]on_implementation_unload().(type_module);
42 }
43 }
44 }
45
46 // an enum to register as a dynamic type.
47 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, glibrust-analyzer cargo glib 0.22.5 crate/::Enumrust-analyzer cargo glib-macros 0.22.2 Enum:)]
48 #[repr(u32)]
49 #[enum_type(name = "MyModuleEnum")]
50 #[enum_dynamic]
51 pub enum MyModuleEnumrust-analyzer cargo glib-macros 0.22.6 module/MyModuleEnum# {
52 #[enum_valuerust-analyzer cargo glib-macros 0.22.2 enum_value:(name = "Foo")]
53 Foorust-analyzer cargo glib-macros 0.22.6 module/MyModuleEnum#Foo#,
54 Barrust-analyzer cargo glib-macros 0.22.6 module/MyModuleEnum#Bar#,
55 }
56
57 // an enum to lazy register as a dynamic type.
58 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, glibrust-analyzer cargo glib 0.22.5 crate/::Enumrust-analyzer cargo glib-macros 0.22.2 Enum:)]
59 #[repr(u32)]
60 #[enum_type(name = "MyModuleEnumLazy")]
61 #[enum_dynamic(lazy_registration = true)]
62 pub enum MyModuleEnumLazyrust-analyzer cargo glib-macros 0.22.6 module/MyModuleEnumLazy# {
63 #[enum_valuerust-analyzer cargo glib-macros 0.22.2 enum_value:(name = "Foo")]
64 Foorust-analyzer cargo glib-macros 0.22.6 module/MyModuleEnumLazy#Foo#,
65 Barrust-analyzer cargo glib-macros 0.22.6 module/MyModuleEnumLazy#Bar#,
66 }
67
68 // a module (must extend `glib::TypeModule` and must implement `glib::TypePlugin`).
69 glibrust-analyzer cargo glib 0.22.5 crate/::wrapperrust-analyzer cargo glib 0.22.5 wrapper/wrapper!! {
70 pub struct MyModulerust-analyzer cargo glib-macros 0.22.6 module/MyModule#(ObjectSubclass<imprust-analyzer cargo glib-macros 0.22.6 module/imp/::MyModulerust-analyzer cargo glib-macros 0.22.6 module/imp/MyModule#>)
71 @extends glibrust-analyzer cargo glib 0.22.5 crate/::TypeModulerust-analyzer cargo glib 0.22.5 gobject/type_module/TypeModule#, @implements glibrust-analyzer cargo glib 0.22.5 crate/::TypePluginrust-analyzer cargo glib 0.22.5 gobject/type_plugin/TypePlugin#;
72 }
73
74 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
75 fn dynamic_enumsrust-analyzer cargo glib-macros 0.22.6 module/dynamic_enums().() {
76 // 1st: creates a single module to test with.
77 let module = glibrust-analyzer cargo glib 0.22.5 crate/::Objectrust-analyzer cargo glib 0.22.5 object/Object#::newrust-analyzer cargo glib 0.22.5 object/impl#[Object]new().::<MyModulerust-analyzer cargo glib-macros 0.22.6 module/MyModule#>();
78 // 1st: uses it to test lifecycle of enums registered as dynamic types.
79 dynamic_enums_lifecyclerust-analyzer cargo glib-macros 0.22.6 module/dynamic_enums_lifecycle().(&module);
80 // 2nd: uses it to test behavior of enums registered as dynamic types.
81 dynamic_enums_behaviorrust-analyzer cargo glib-macros 0.22.6 module/dynamic_enums_behavior().(&module);
82 }
83
84 // tests lifecycle of enums registered as dynamic types within a module.
85 fn dynamic_enums_lifecyclerust-analyzer cargo glib-macros 0.22.6 module/dynamic_enums_lifecycle().(module: &MyModulerust-analyzer cargo glib-macros 0.22.6 module/MyModule#) {
86 // checks types of enums to register as dynamic types are invalid (module is not loaded yet).
87 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().MyModuleEnumrust-analyzer cargo glib-macros 0.22.6 module/MyModuleEnum#::static_typerust-analyzer cargo glib-macros 0.22.6 module/impl#[MyModuleEnum][StaticType]static_type().().is_validrust-analyzer cargo glib 0.22.5 types/impl#[Type]is_valid().());
88 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().MyModuleEnumLazyrust-analyzer cargo glib-macros 0.22.6 module/MyModuleEnumLazy#::static_typerust-analyzer cargo glib-macros 0.22.6 module/impl#[MyModuleEnumLazy][StaticType]static_type().().is_validrust-analyzer cargo glib 0.22.5 types/impl#[Type]is_valid().());
89
90 // simulates the GLib type system to load/unload the module.
91 TypeModuleExtrust-analyzer cargo glib 0.22.5 gobject/type_module/TypeModuleExt#::use_rust-analyzer cargo glib 0.22.5 gobject/type_module/TypeModuleExt#use_().(module);
92 TypeModuleExtrust-analyzer cargo glib 0.22.5 gobject/type_module/TypeModuleExt#::unuserust-analyzer cargo glib 0.22.5 gobject/type_module/TypeModuleExt#unuse().(module);
93
94 // checks types of enums registered as dynamic types are valid (module is unloaded).
95 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(MyModuleEnumrust-analyzer cargo glib-macros 0.22.6 module/MyModuleEnum#::static_typerust-analyzer cargo glib-macros 0.22.6 module/impl#[MyModuleEnum][StaticType]static_type().().is_validrust-analyzer cargo glib 0.22.5 types/impl#[Type]is_valid().());
96 // checks types of enums that are lazy registered as dynamic types are valid (module is unloaded).
97 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().MyModuleEnumLazyrust-analyzer cargo glib-macros 0.22.6 module/MyModuleEnumLazy#::static_typerust-analyzer cargo glib-macros 0.22.6 module/impl#[MyModuleEnumLazy][StaticType]static_type().().is_validrust-analyzer cargo glib 0.22.5 types/impl#[Type]is_valid().());
98
99 // simulates the GLib type system to load the module.
100 TypeModuleExtrust-analyzer cargo glib 0.22.5 gobject/type_module/TypeModuleExt#::use_rust-analyzer cargo glib 0.22.5 gobject/type_module/TypeModuleExt#use_().(module);
101
102 // checks types of enums registered as dynamic types are valid (module is loaded).
103 let enum_type = MyModuleEnumrust-analyzer cargo glib-macros 0.22.6 module/MyModuleEnum#::static_typerust-analyzer cargo glib-macros 0.22.6 module/impl#[MyModuleEnum][StaticType]static_type().();
104 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(enum_type.is_validrust-analyzer cargo glib 0.22.5 types/impl#[Type]is_valid().());
105 let enum_lazy_type = MyModuleEnumLazyrust-analyzer cargo glib-macros 0.22.6 module/MyModuleEnumLazy#::static_typerust-analyzer cargo glib-macros 0.22.6 module/impl#[MyModuleEnumLazy][StaticType]static_type().();
106 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(enum_lazy_type.is_validrust-analyzer cargo glib 0.22.5 types/impl#[Type]is_valid().());
107
108 // checks plugin of enums registered as dynamic types is `MyModule`.
109 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
110 enum_type.pluginrust-analyzer cargo glib 0.22.5 types/impl#[Type]plugin().().as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().(),
111 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(module.upcast_refrust-analyzer cargo glib 0.22.5 object/Cast#upcast_ref().::<glibrust-analyzer cargo glib 0.22.5 crate/::TypePluginrust-analyzer cargo glib 0.22.5 gobject/type_plugin/TypePlugin#>())
112 );
113 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
114 enum_lazy_type.pluginrust-analyzer cargo glib 0.22.5 types/impl#[Type]plugin().().as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().(),
115 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(module.upcast_refrust-analyzer cargo glib 0.22.5 object/Cast#upcast_ref().::<glibrust-analyzer cargo glib 0.22.5 crate/::TypePluginrust-analyzer cargo glib 0.22.5 gobject/type_plugin/TypePlugin#>())
116 );
117
118 // simulates the GLib type system to unload the module.
119 TypeModuleExtrust-analyzer cargo glib 0.22.5 gobject/type_module/TypeModuleExt#::unuserust-analyzer cargo glib 0.22.5 gobject/type_module/TypeModuleExt#unuse().(module);
120
121 // checks types of enums registered as dynamic types are still valid (should have been marked as unloaded by the GLib type system but this cannot be checked).
122 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(MyModuleEnumrust-analyzer cargo glib-macros 0.22.6 module/MyModuleEnum#::static_typerust-analyzer cargo glib-macros 0.22.6 module/impl#[MyModuleEnum][StaticType]static_type().().is_validrust-analyzer cargo glib 0.22.5 types/impl#[Type]is_valid().());
123 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(MyModuleEnumLazyrust-analyzer cargo glib-macros 0.22.6 module/MyModuleEnumLazy#::static_typerust-analyzer cargo glib-macros 0.22.6 module/impl#[MyModuleEnumLazy][StaticType]static_type().().is_validrust-analyzer cargo glib 0.22.5 types/impl#[Type]is_valid().());
124
125 // simulates the GLib type system to reload the module.
126 TypeModuleExtrust-analyzer cargo glib 0.22.5 gobject/type_module/TypeModuleExt#::use_rust-analyzer cargo glib 0.22.5 gobject/type_module/TypeModuleExt#use_().(module);
127
128 // checks types of enums registered as dynamic types are still valid (should have been marked as loaded by the GLib type system but this cannot be checked).
129 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(MyModuleEnumrust-analyzer cargo glib-macros 0.22.6 module/MyModuleEnum#::static_typerust-analyzer cargo glib-macros 0.22.6 module/impl#[MyModuleEnum][StaticType]static_type().().is_validrust-analyzer cargo glib 0.22.5 types/impl#[Type]is_valid().());
130 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(MyModuleEnumLazyrust-analyzer cargo glib-macros 0.22.6 module/MyModuleEnumLazy#::static_typerust-analyzer cargo glib-macros 0.22.6 module/impl#[MyModuleEnumLazy][StaticType]static_type().().is_validrust-analyzer cargo glib 0.22.5 types/impl#[Type]is_valid().());
131
132 // simulates the GLib type system to unload the module.
133 TypeModuleExtrust-analyzer cargo glib 0.22.5 gobject/type_module/TypeModuleExt#::unuserust-analyzer cargo glib 0.22.5 gobject/type_module/TypeModuleExt#unuse().(module);
134 }
135
136 // tests behavior of enums registered as dynamic types within a module.
137 fn dynamic_enums_behaviorrust-analyzer cargo glib-macros 0.22.6 module/dynamic_enums_behavior().(module: &MyModulerust-analyzer cargo glib-macros 0.22.6 module/MyModule#) {
138 use glibrust-analyzer cargo glib 0.22.5 crate/::preluderust-analyzer cargo glib 0.22.5 prelude/::*;
139 use glibrust-analyzer cargo glib 0.22.5 crate/::translaterust-analyzer cargo glib 0.22.5 translate/::{FromGlibrust-analyzer cargo glib 0.22.5 translate/FromGlib#, IntoGlibrust-analyzer cargo glib 0.22.5 translate/IntoGlib#};
140
141 // simulates the GLib type system to load the module.
142 TypeModuleExtrust-analyzer cargo glib 0.22.5 gobject/type_module/TypeModuleExt#::use_rust-analyzer cargo glib 0.22.5 gobject/type_module/TypeModuleExt#use_().(module);
143
144 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(MyModuleEnumrust-analyzer cargo glib-macros 0.22.6 module/MyModuleEnum#::Foorust-analyzer cargo glib-macros 0.22.6 module/MyModuleEnum#Foo#.into_glibrust-analyzer cargo glib-macros 0.22.6 module/impl#[MyModuleEnum][IntoGlib]into_glib().(), 0);
145 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(MyModuleEnumrust-analyzer cargo glib-macros 0.22.6 module/MyModuleEnum#::Barrust-analyzer cargo glib-macros 0.22.6 module/MyModuleEnum#Bar#.into_glibrust-analyzer cargo glib-macros 0.22.6 module/impl#[MyModuleEnum][IntoGlib]into_glib().(), 1);
146
147 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(unsafe { MyModuleEnumrust-analyzer cargo glib-macros 0.22.6 module/MyModuleEnum#::from_glibrust-analyzer cargo glib-macros 0.22.6 module/impl#[MyModuleEnum][`FromGlib<i32>`]from_glib().(0) }, MyModuleEnumrust-analyzer cargo glib-macros 0.22.6 module/MyModuleEnum#::Foorust-analyzer cargo glib-macros 0.22.6 module/MyModuleEnum#Foo#);
148 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(unsafe { MyModuleEnumrust-analyzer cargo glib-macros 0.22.6 module/MyModuleEnum#::from_glibrust-analyzer cargo glib-macros 0.22.6 module/impl#[MyModuleEnum][`FromGlib<i32>`]from_glib().(1) }, MyModuleEnumrust-analyzer cargo glib-macros 0.22.6 module/MyModuleEnum#::Barrust-analyzer cargo glib-macros 0.22.6 module/MyModuleEnum#Bar#);
149
150 let t = MyModuleEnumrust-analyzer cargo glib-macros 0.22.6 module/MyModuleEnum#::static_typerust-analyzer cargo glib-macros 0.22.6 module/impl#[MyModuleEnum][StaticType]static_type().();
151 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(t.is_arust-analyzer cargo glib 0.22.5 types/impl#[Type]is_a().(glibrust-analyzer cargo glib 0.22.5 crate/::Typerust-analyzer cargo glib 0.22.5 types/Type#::ENUMrust-analyzer cargo glib 0.22.5 types/impl#[Type]ENUM.));
152 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(t.namerust-analyzer cargo glib 0.22.5 types/impl#[Type]name().(), "MyModuleEnum");
153
154 let e = glibrust-analyzer cargo glib 0.22.5 crate/::EnumClassrust-analyzer cargo glib 0.22.5 enums/EnumClass#::with_typerust-analyzer cargo glib 0.22.5 enums/impl#[EnumClass]with_type().(t).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("EnumClass::new failed");
155
156 let values = e.valuesrust-analyzer cargo glib 0.22.5 enums/impl#[EnumClass]values().();
157 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(values.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().(), 2);
158 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(values[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()..namerust-analyzer cargo glib 0.22.5 enums/impl#[EnumValue]name().(), "Foo");
159 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(values[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()..nickrust-analyzer cargo glib 0.22.5 enums/impl#[EnumValue]nick().(), "foo");
160 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(values[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().1]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()..namerust-analyzer cargo glib 0.22.5 enums/impl#[EnumValue]name().(), "Bar");
161 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(values[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().1]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()..nickrust-analyzer cargo glib 0.22.5 enums/impl#[EnumValue]nick().(), "bar");
162
163 let v = e.valuerust-analyzer cargo glib 0.22.5 enums/impl#[EnumClass]value().(0).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("EnumClass::get_value(0) failed");
164 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(v.namerust-analyzer cargo glib 0.22.5 enums/impl#[EnumValue]name().(), "Foo");
165 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(v.nickrust-analyzer cargo glib 0.22.5 enums/impl#[EnumValue]nick().(), "foo");
166 let v = e.valuerust-analyzer cargo glib 0.22.5 enums/impl#[EnumClass]value().(1).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("EnumClass::get_value(1) failed");
167 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(v.namerust-analyzer cargo glib 0.22.5 enums/impl#[EnumValue]name().(), "Bar");
168 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(v.nickrust-analyzer cargo glib 0.22.5 enums/impl#[EnumValue]nick().(), "bar");
169 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(e.valuerust-analyzer cargo glib 0.22.5 enums/impl#[EnumClass]value().(2), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
170
171 // within enums registered as dynamic types, values are usables only if
172 // at least one type class ref exists (see `glib::EnumClass`).
173 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
174 MyModuleEnumrust-analyzer cargo glib-macros 0.22.6 module/MyModuleEnum#::Foorust-analyzer cargo glib-macros 0.22.6 module/MyModuleEnum#Foo#.to_valuerust-analyzer cargo glib-macros 0.22.6 module/impl#[MyModuleEnum][ToValue]to_value().().getrust-analyzer cargo glib 0.22.5 value/impl#[Value]get().::<MyModuleEnumrust-analyzer cargo glib-macros 0.22.6 module/MyModuleEnum#>(),
175 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(MyModuleEnumrust-analyzer cargo glib-macros 0.22.6 module/MyModuleEnum#::Foorust-analyzer cargo glib-macros 0.22.6 module/MyModuleEnum#Foo#)
176 );
177 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
178 MyModuleEnumrust-analyzer cargo glib-macros 0.22.6 module/MyModuleEnum#::Barrust-analyzer cargo glib-macros 0.22.6 module/MyModuleEnum#Bar#.to_valuerust-analyzer cargo glib-macros 0.22.6 module/impl#[MyModuleEnum][ToValue]to_value().().getrust-analyzer cargo glib 0.22.5 value/impl#[Value]get().::<MyModuleEnumrust-analyzer cargo glib-macros 0.22.6 module/MyModuleEnum#>(),
179 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(MyModuleEnumrust-analyzer cargo glib-macros 0.22.6 module/MyModuleEnum#::Barrust-analyzer cargo glib-macros 0.22.6 module/MyModuleEnum#Bar#)
180 );
181
182 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(MyModuleEnumLazyrust-analyzer cargo glib-macros 0.22.6 module/MyModuleEnumLazy#::Foorust-analyzer cargo glib-macros 0.22.6 module/MyModuleEnumLazy#Foo#.into_glibrust-analyzer cargo glib-macros 0.22.6 module/impl#[MyModuleEnumLazy][IntoGlib]into_glib().(), 0);
183 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(MyModuleEnumLazyrust-analyzer cargo glib-macros 0.22.6 module/MyModuleEnumLazy#::Barrust-analyzer cargo glib-macros 0.22.6 module/MyModuleEnumLazy#Bar#.into_glibrust-analyzer cargo glib-macros 0.22.6 module/impl#[MyModuleEnumLazy][IntoGlib]into_glib().(), 1);
184
185 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
186 unsafe { MyModuleEnumLazyrust-analyzer cargo glib-macros 0.22.6 module/MyModuleEnumLazy#::from_glibrust-analyzer cargo glib-macros 0.22.6 module/impl#[MyModuleEnumLazy][`FromGlib<i32>`]from_glib().(0) },
187 MyModuleEnumLazyrust-analyzer cargo glib-macros 0.22.6 module/MyModuleEnumLazy#::Foorust-analyzer cargo glib-macros 0.22.6 module/MyModuleEnumLazy#Foo#
188 );
189 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
190 unsafe { MyModuleEnumLazyrust-analyzer cargo glib-macros 0.22.6 module/MyModuleEnumLazy#::from_glibrust-analyzer cargo glib-macros 0.22.6 module/impl#[MyModuleEnumLazy][`FromGlib<i32>`]from_glib().(1) },
191 MyModuleEnumLazyrust-analyzer cargo glib-macros 0.22.6 module/MyModuleEnumLazy#::Barrust-analyzer cargo glib-macros 0.22.6 module/MyModuleEnumLazy#Bar#
192 );
193
194 let t = MyModuleEnumLazyrust-analyzer cargo glib-macros 0.22.6 module/MyModuleEnumLazy#::static_typerust-analyzer cargo glib-macros 0.22.6 module/impl#[MyModuleEnumLazy][StaticType]static_type().();
195 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(t.is_arust-analyzer cargo glib 0.22.5 types/impl#[Type]is_a().(glibrust-analyzer cargo glib 0.22.5 crate/::Typerust-analyzer cargo glib 0.22.5 types/Type#::ENUMrust-analyzer cargo glib 0.22.5 types/impl#[Type]ENUM.));
196 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(t.namerust-analyzer cargo glib 0.22.5 types/impl#[Type]name().(), "MyModuleEnumLazy");
197
198 let e = glibrust-analyzer cargo glib 0.22.5 crate/::EnumClassrust-analyzer cargo glib 0.22.5 enums/EnumClass#::with_typerust-analyzer cargo glib 0.22.5 enums/impl#[EnumClass]with_type().(t).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("EnumClass::new failed");
199
200 let values = e.valuesrust-analyzer cargo glib 0.22.5 enums/impl#[EnumClass]values().();
201 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(values.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().(), 2);
202 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(values[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()..namerust-analyzer cargo glib 0.22.5 enums/impl#[EnumValue]name().(), "Foo");
203 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(values[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()..nickrust-analyzer cargo glib 0.22.5 enums/impl#[EnumValue]nick().(), "foo");
204 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(values[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().1]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()..namerust-analyzer cargo glib 0.22.5 enums/impl#[EnumValue]name().(), "Bar");
205 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(values[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().1]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()..nickrust-analyzer cargo glib 0.22.5 enums/impl#[EnumValue]nick().(), "bar");
206
207 let v = e.valuerust-analyzer cargo glib 0.22.5 enums/impl#[EnumClass]value().(0).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("EnumClass::get_value(0) failed");
208 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(v.namerust-analyzer cargo glib 0.22.5 enums/impl#[EnumValue]name().(), "Foo");
209 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(v.nickrust-analyzer cargo glib 0.22.5 enums/impl#[EnumValue]nick().(), "foo");
210 let v = e.valuerust-analyzer cargo glib 0.22.5 enums/impl#[EnumClass]value().(1).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("EnumClass::get_value(1) failed");
211 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(v.namerust-analyzer cargo glib 0.22.5 enums/impl#[EnumValue]name().(), "Bar");
212 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(v.nickrust-analyzer cargo glib 0.22.5 enums/impl#[EnumValue]nick().(), "bar");
213 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(e.valuerust-analyzer cargo glib 0.22.5 enums/impl#[EnumClass]value().(2), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
214
215 // within enums registered as dynamic types, values are usables only if
216 // at least one type class ref exists (see `glib::EnumClass`).
217 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
218 MyModuleEnumLazyrust-analyzer cargo glib-macros 0.22.6 module/MyModuleEnumLazy#::Foorust-analyzer cargo glib-macros 0.22.6 module/MyModuleEnumLazy#Foo#.to_valuerust-analyzer cargo glib-macros 0.22.6 module/impl#[MyModuleEnumLazy][ToValue]to_value().().getrust-analyzer cargo glib 0.22.5 value/impl#[Value]get().::<MyModuleEnumLazyrust-analyzer cargo glib-macros 0.22.6 module/MyModuleEnumLazy#>(),
219 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(MyModuleEnumLazyrust-analyzer cargo glib-macros 0.22.6 module/MyModuleEnumLazy#::Foorust-analyzer cargo glib-macros 0.22.6 module/MyModuleEnumLazy#Foo#)
220 );
221 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
222 MyModuleEnumLazyrust-analyzer cargo glib-macros 0.22.6 module/MyModuleEnumLazy#::Barrust-analyzer cargo glib-macros 0.22.6 module/MyModuleEnumLazy#Bar#.to_valuerust-analyzer cargo glib-macros 0.22.6 module/impl#[MyModuleEnumLazy][ToValue]to_value().().getrust-analyzer cargo glib 0.22.5 value/impl#[Value]get().::<MyModuleEnumLazyrust-analyzer cargo glib-macros 0.22.6 module/MyModuleEnumLazy#>(),
223 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(MyModuleEnumLazyrust-analyzer cargo glib-macros 0.22.6 module/MyModuleEnumLazy#::Barrust-analyzer cargo glib-macros 0.22.6 module/MyModuleEnumLazy#Bar#)
224 );
225
226 // simulates the GLib type system to unload the module.
227 TypeModuleExtrust-analyzer cargo glib 0.22.5 gobject/type_module/TypeModuleExt#::unuserust-analyzer cargo glib 0.22.5 gobject/type_module/TypeModuleExt#unuse().(module);
228 }
229 }
230
231 pub mod pluginrust-analyzer cargo glib-macros 0.22.6 plugin/ {
232 use superrust-analyzer cargo glib-macros 0.22.6 crate/::*;
233
234 pub mod imprust-analyzer cargo glib-macros 0.22.6 plugin/imp/ {
235 use glibrust-analyzer cargo glib 0.22.5 crate/::EnumClassrust-analyzer cargo glib 0.22.5 enums/EnumClass#;
236
237 use superrust-analyzer cargo glib-macros 0.22.6 plugin/::*;
238 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::cellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/::Cellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/Cell#;
239
240 // impl for a type plugin (must implement `glib::TypePlugin`).
241 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default:)]
242 pub struct MyPluginrust-analyzer cargo glib-macros 0.22.6 plugin/imp/MyPlugin# {
243 my_enum_type_valuesrust-analyzer cargo glib-macros 0.22.6 plugin/imp/MyPlugin#my_enum_type_values.: Cellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/Cell#<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&'static glibrust-analyzer cargo glib 0.22.5 crate/::enumsrust-analyzer cargo glib 0.22.5 enums/::EnumValuesrust-analyzer cargo glib 0.22.5 enums/EnumValues#>>,
244 my_enum_lazy_type_valuesrust-analyzer cargo glib-macros 0.22.6 plugin/imp/MyPlugin#my_enum_lazy_type_values.: Cellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/Cell#<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&'static glibrust-analyzer cargo glib 0.22.5 crate/::enumsrust-analyzer cargo glib 0.22.5 enums/::EnumValuesrust-analyzer cargo glib 0.22.5 enums/EnumValues#>>,
245 }
246
247 #[glibrust-analyzer cargo glib 0.22.5 crate/::object_subclassrust-analyzer cargo glib-macros 0.22.2 object_subclass:]
248 impl ObjectSubclassrust-analyzer cargo glib 0.22.5 subclass/types/ObjectSubclass# for MyPluginrust-analyzer cargo glib-macros 0.22.6 plugin/imp/MyPlugin# {
249 const NAMErust-analyzer cargo glib-macros 0.22.6 plugin/imp/impl#[MyPlugin][ObjectSubclass]NAME.: &'static str = "MyPlugin";
250 type Typerust-analyzer cargo glib-macros 0.22.6 plugin/imp/impl#[MyPlugin][ObjectSubclass]Type# = superrust-analyzer cargo glib-macros 0.22.6 plugin/::MyPluginrust-analyzer cargo glib-macros 0.22.6 plugin/MyPlugin#;
251 type Interfacesrust-analyzer cargo glib-macros 0.22.6 plugin/imp/impl#[MyPlugin][ObjectSubclass]Interfaces# = (glibrust-analyzer cargo glib 0.22.5 crate/::TypePluginrust-analyzer cargo glib 0.22.5 gobject/type_plugin/TypePlugin#,);
252 }
253
254 impl ObjectImplrust-analyzer cargo glib 0.22.5 subclass/object/ObjectImpl# for MyPluginrust-analyzer cargo glib-macros 0.22.6 plugin/imp/MyPlugin# {}
255
256 impl TypePluginImplrust-analyzer cargo glib 0.22.5 subclass/type_plugin/TypePluginImpl# for MyPluginrust-analyzer cargo glib-macros 0.22.6 plugin/imp/MyPlugin# {
257 fn use_pluginrust-analyzer cargo glib-macros 0.22.6 plugin/imp/impl#[MyPlugin][TypePluginImpl]use_plugin().(&self) {
258 // register enums as dynamic types.
259 let my_plugin = self.objrust-analyzer cargo glib 0.22.5 subclass/types/impl#[T][ObjectSubclassExt]obj().();
260 superrust-analyzer cargo glib-macros 0.22.6 plugin/::MyPluginEnumrust-analyzer cargo glib-macros 0.22.6 plugin/MyPluginEnum#::on_implementation_loadrust-analyzer cargo glib-macros 0.22.6 plugin/impl#[MyPluginEnum]on_implementation_load().(my_plugin.as_refrust-analyzer cargo glib 0.22.5 object/impl#[`BorrowedObject<'_, T>`][`AsRef<T>`]as_ref().());
261 superrust-analyzer cargo glib-macros 0.22.6 plugin/::MyPluginEnumLazyrust-analyzer cargo glib-macros 0.22.6 plugin/MyPluginEnumLazy#::on_implementation_loadrust-analyzer cargo glib-macros 0.22.6 plugin/impl#[MyPluginEnumLazy]on_implementation_load().(my_plugin.as_refrust-analyzer cargo glib 0.22.5 object/impl#[`BorrowedObject<'_, T>`][`AsRef<T>`]as_ref().());
262 }
263
264 fn unuse_pluginrust-analyzer cargo glib-macros 0.22.6 plugin/imp/impl#[MyPlugin][TypePluginImpl]unuse_plugin().(&self) {
265 // marks enums as unregistered.
266 let my_plugin = self.objrust-analyzer cargo glib 0.22.5 subclass/types/impl#[T][ObjectSubclassExt]obj().();
267 superrust-analyzer cargo glib-macros 0.22.6 plugin/::MyPluginEnumLazyrust-analyzer cargo glib-macros 0.22.6 plugin/MyPluginEnumLazy#::on_implementation_unloadrust-analyzer cargo glib-macros 0.22.6 plugin/impl#[MyPluginEnumLazy]on_implementation_unload().(my_plugin.as_refrust-analyzer cargo glib 0.22.5 object/impl#[`BorrowedObject<'_, T>`][`AsRef<T>`]as_ref().());
268 superrust-analyzer cargo glib-macros 0.22.6 plugin/::MyPluginEnumrust-analyzer cargo glib-macros 0.22.6 plugin/MyPluginEnum#::on_implementation_unloadrust-analyzer cargo glib-macros 0.22.6 plugin/impl#[MyPluginEnum]on_implementation_unload().(my_plugin.as_refrust-analyzer cargo glib 0.22.5 object/impl#[`BorrowedObject<'_, T>`][`AsRef<T>`]as_ref().());
269 }
270
271 fn complete_type_inforust-analyzer cargo glib-macros 0.22.6 plugin/imp/impl#[MyPlugin][TypePluginImpl]complete_type_info().(
272 &self,
273 type_: glibrust-analyzer cargo glib 0.22.5 crate/::Typerust-analyzer cargo glib 0.22.5 types/Type#,
274 ) -> (glibrust-analyzer cargo glib 0.22.5 crate/::TypeInforust-analyzer cargo glib 0.22.5 gobject/type_info/TypeInfo#, glibrust-analyzer cargo glib 0.22.5 crate/::TypeValueTablerust-analyzer cargo glib 0.22.5 gobject/type_value_table/TypeValueTable#) {
275 let enum_type_values = match type_ {
276 type_ if type_ rust-analyzer cargo glib 0.22.5 types/impl#[Type][`PartialEq<Self>`]eq().==rust-analyzer cargo glib 0.22.5 types/impl#[Type][`PartialEq<Self>`]eq(). rust-analyzer cargo glib 0.22.5 types/impl#[Type][`PartialEq<Self>`]eq().superrust-analyzer cargo glib-macros 0.22.6 plugin/::MyPluginEnumrust-analyzer cargo glib-macros 0.22.6 plugin/MyPluginEnum#::static_typerust-analyzer cargo glib-macros 0.22.6 plugin/impl#[MyPluginEnum][StaticType]static_type().() => {
277 self.my_enum_type_valuesrust-analyzer cargo glib-macros 0.22.6 plugin/imp/MyPlugin#my_enum_type_values..getrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`Cell<T>`]get().()
278 }
279 type_ if type_ rust-analyzer cargo glib 0.22.5 types/impl#[Type][`PartialEq<Self>`]eq().==rust-analyzer cargo glib 0.22.5 types/impl#[Type][`PartialEq<Self>`]eq(). rust-analyzer cargo glib 0.22.5 types/impl#[Type][`PartialEq<Self>`]eq().superrust-analyzer cargo glib-macros 0.22.6 plugin/::MyPluginEnumLazyrust-analyzer cargo glib-macros 0.22.6 plugin/MyPluginEnumLazy#::static_typerust-analyzer cargo glib-macros 0.22.6 plugin/impl#[MyPluginEnumLazy][StaticType]static_type().() => {
280 self.my_enum_lazy_type_valuesrust-analyzer cargo glib-macros 0.22.6 plugin/imp/MyPlugin#my_enum_lazy_type_values..getrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`Cell<T>`]get().()
281 }
282 _ => panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("unexpected type"),
283 }
284 .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("enum type values");
285 let type_info = EnumClassrust-analyzer cargo glib 0.22.5 enums/EnumClass#::complete_type_inforust-analyzer cargo glib 0.22.5 enums/impl#[EnumClass]complete_type_info().(type_, enum_type_values)
286 .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("EnumClass::complete_type_info failed");
287 (type_info, glibrust-analyzer cargo glib 0.22.5 crate/::TypeValueTablerust-analyzer cargo glib 0.22.5 gobject/type_value_table/TypeValueTable#::defaultrust-analyzer cargo glib 0.22.5 gobject/type_value_table/impl#[TypeValueTable][Default]default().())
288 }
289 }
290
291 impl TypePluginRegisterImplrust-analyzer cargo glib 0.22.5 subclass/type_plugin/TypePluginRegisterImpl# for MyPluginrust-analyzer cargo glib-macros 0.22.6 plugin/imp/MyPlugin# {
292 fn register_dynamic_enumrust-analyzer cargo glib-macros 0.22.6 plugin/imp/impl#[MyPlugin][TypePluginRegisterImpl]register_dynamic_enum().(
293 &self,
294 type_name: &str,
295 const_static_values: &'static glibrust-analyzer cargo glib 0.22.5 crate/::enumsrust-analyzer cargo glib 0.22.5 enums/::EnumValuesrust-analyzer cargo glib 0.22.5 enums/EnumValues#,
296 ) -> glibrust-analyzer cargo glib 0.22.5 crate/::Typerust-analyzer cargo glib 0.22.5 types/Type# {
297 let type_ = glibrust-analyzer cargo glib 0.22.5 crate/::Typerust-analyzer cargo glib 0.22.5 types/Type#::from_namerust-analyzer cargo glib 0.22.5 types/impl#[Type]from_name().(type_name).unwrap_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or_else().(|| {
298 glibrust-analyzer cargo glib 0.22.5 crate/::Typerust-analyzer cargo glib 0.22.5 types/Type#::register_dynamicrust-analyzer cargo glib 0.22.5 types/impl#[Type]register_dynamic().(
299 glibrust-analyzer cargo glib 0.22.5 crate/::Typerust-analyzer cargo glib 0.22.5 types/Type#::ENUMrust-analyzer cargo glib 0.22.5 types/impl#[Type]ENUM.,
300 type_name,
301 self.objrust-analyzer cargo glib 0.22.5 subclass/types/impl#[T][ObjectSubclassExt]obj().().upcast_refrust-analyzer cargo glib 0.22.5 object/Cast#upcast_ref().::<glibrust-analyzer cargo glib 0.22.5 crate/::TypePluginrust-analyzer cargo glib 0.22.5 gobject/type_plugin/TypePlugin#>(),
302 glibrust-analyzer cargo glib 0.22.5 crate/::TypeFlagsrust-analyzer cargo glib 0.22.5 gobject/auto/flags/TypeFlags#::NONErust-analyzer cargo glib 0.22.5 gobject/auto/flags/impl#[TypeFlags]NONE.,
303 )
304 });
305 if type_.is_validrust-analyzer cargo glib 0.22.5 types/impl#[Type]is_valid().() {
306 match type_name {
307 "MyPluginEnum" => self.my_enum_type_valuesrust-analyzer cargo glib-macros 0.22.6 plugin/imp/MyPlugin#my_enum_type_values..setrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`Cell<T>`]set().(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(const_static_values)),
308 "MyPluginEnumLazy" => {
309 self.my_enum_lazy_type_valuesrust-analyzer cargo glib-macros 0.22.6 plugin/imp/MyPlugin#my_enum_lazy_type_values..setrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`Cell<T>`]set().(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(const_static_values))
310 }
311 _ => panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("unexpected"),
312 };
313 }
314 type_
315 }
316 }
317 }
318
319 // an enum to register as a dynamic type.
320 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, glibrust-analyzer cargo glib 0.22.5 crate/::Enumrust-analyzer cargo glib-macros 0.22.2 Enum:)]
321 #[repr(u32)]
322 #[enum_type(name = "MyPluginEnum")]
323 #[enum_dynamic(plugin_type = MyPluginrust-analyzer cargo glib-macros 0.22.6 plugin/MyPlugin#)]
324 pub enum MyPluginEnumrust-analyzer cargo glib-macros 0.22.6 plugin/MyPluginEnum# {
325 #[enum_valuerust-analyzer cargo glib-macros 0.22.2 enum_value:(name = "Foo")]
326 Foorust-analyzer cargo glib-macros 0.22.6 plugin/MyPluginEnum#Foo#,
327 Barrust-analyzer cargo glib-macros 0.22.6 plugin/MyPluginEnum#Bar#,
328 }
329
330 // an enum to lazy register as a dynamic type.
331 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, glibrust-analyzer cargo glib 0.22.5 crate/::Enumrust-analyzer cargo glib-macros 0.22.2 Enum:)]
332 #[repr(u32)]
333 #[enum_type(name = "MyPluginEnumLazy")]
334 #[enum_dynamic(plugin_type = MyPluginrust-analyzer cargo glib-macros 0.22.6 plugin/MyPlugin#, lazy_registration = true)]
335 pub enum MyPluginEnumLazyrust-analyzer cargo glib-macros 0.22.6 plugin/MyPluginEnumLazy# {
336 #[enum_valuerust-analyzer cargo glib-macros 0.22.2 enum_value:(name = "Foo")]
337 Foorust-analyzer cargo glib-macros 0.22.6 plugin/MyPluginEnumLazy#Foo#,
338 Barrust-analyzer cargo glib-macros 0.22.6 plugin/MyPluginEnumLazy#Bar#,
339 }
340
341 // a plugin (must implement `glib::TypePlugin`).
342 glibrust-analyzer cargo glib 0.22.5 crate/::wrapperrust-analyzer cargo glib 0.22.5 wrapper/wrapper!! {
343 pub struct MyPluginrust-analyzer cargo glib-macros 0.22.6 plugin/MyPlugin#(ObjectSubclass<imprust-analyzer cargo glib-macros 0.22.6 plugin/imp/::MyPluginrust-analyzer cargo glib-macros 0.22.6 plugin/imp/MyPlugin#>) @implements glibrust-analyzer cargo glib 0.22.5 crate/::TypePluginrust-analyzer cargo glib 0.22.5 gobject/type_plugin/TypePlugin#;
344 }
345
346 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
347 fn dynamic_enumsrust-analyzer cargo glib-macros 0.22.6 plugin/dynamic_enums().() {
348 // 1st: creates a single plugin to test with.
349 let plugin = glibrust-analyzer cargo glib 0.22.5 crate/::Objectrust-analyzer cargo glib 0.22.5 object/Object#::newrust-analyzer cargo glib 0.22.5 object/impl#[Object]new().::<MyPluginrust-analyzer cargo glib-macros 0.22.6 plugin/MyPlugin#>();
350 // 1st: uses it to test lifecycle of enums registered as dynamic types.
351 dynamic_enums_lifecyclerust-analyzer cargo glib-macros 0.22.6 plugin/dynamic_enums_lifecycle().(&plugin);
352 // 2nd: uses it to test behavior of enums registered as dynamic types.
353 dynamic_enums_behaviorrust-analyzer cargo glib-macros 0.22.6 plugin/dynamic_enums_behavior().(&plugin);
354 }
355
356 // tests lifecycle of enums registered as dynamic types within a plugin.
357 fn dynamic_enums_lifecyclerust-analyzer cargo glib-macros 0.22.6 plugin/dynamic_enums_lifecycle().(plugin: &MyPluginrust-analyzer cargo glib-macros 0.22.6 plugin/MyPlugin#) {
358 use glibrust-analyzer cargo glib 0.22.5 crate/::preluderust-analyzer cargo glib 0.22.5 prelude/::*;
359
360 // checks types of enums to register as dynamic types are invalid (plugin is not used yet).
361 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().MyPluginEnumrust-analyzer cargo glib-macros 0.22.6 plugin/MyPluginEnum#::static_typerust-analyzer cargo glib-macros 0.22.6 plugin/impl#[MyPluginEnum][StaticType]static_type().().is_validrust-analyzer cargo glib 0.22.5 types/impl#[Type]is_valid().());
362 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().MyPluginEnumLazyrust-analyzer cargo glib-macros 0.22.6 plugin/MyPluginEnumLazy#::static_typerust-analyzer cargo glib-macros 0.22.6 plugin/impl#[MyPluginEnumLazy][StaticType]static_type().().is_validrust-analyzer cargo glib 0.22.5 types/impl#[Type]is_valid().());
363
364 // simulates the GLib type system to use/unuse the plugin.
365 TypePluginExtrust-analyzer cargo glib 0.22.5 gobject/type_plugin/TypePluginExt#::use_rust-analyzer cargo glib 0.22.5 gobject/type_plugin/TypePluginExt#use_().(plugin);
366 TypePluginExtrust-analyzer cargo glib 0.22.5 gobject/type_plugin/TypePluginExt#::unuserust-analyzer cargo glib 0.22.5 gobject/type_plugin/TypePluginExt#unuse().(plugin);
367
368 // checks types of enums registered as dynamic types are valid (plugin is unused).
369 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(MyPluginEnumrust-analyzer cargo glib-macros 0.22.6 plugin/MyPluginEnum#::static_typerust-analyzer cargo glib-macros 0.22.6 plugin/impl#[MyPluginEnum][StaticType]static_type().().is_validrust-analyzer cargo glib 0.22.5 types/impl#[Type]is_valid().());
370 // checks types of enums that are lazy registered as dynamic types are still invalid (plugin is unused).
371 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().MyPluginEnumLazyrust-analyzer cargo glib-macros 0.22.6 plugin/MyPluginEnumLazy#::static_typerust-analyzer cargo glib-macros 0.22.6 plugin/impl#[MyPluginEnumLazy][StaticType]static_type().().is_validrust-analyzer cargo glib 0.22.5 types/impl#[Type]is_valid().());
372
373 // simulates the GLib type system to use the plugin.
374 TypePluginExtrust-analyzer cargo glib 0.22.5 gobject/type_plugin/TypePluginExt#::use_rust-analyzer cargo glib 0.22.5 gobject/type_plugin/TypePluginExt#use_().(plugin);
375
376 // checks types of enums registered as dynamic types are valid (plugin is used).
377 let enum_type = MyPluginEnumrust-analyzer cargo glib-macros 0.22.6 plugin/MyPluginEnum#::static_typerust-analyzer cargo glib-macros 0.22.6 plugin/impl#[MyPluginEnum][StaticType]static_type().();
378 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(enum_type.is_validrust-analyzer cargo glib 0.22.5 types/impl#[Type]is_valid().());
379 let enum_lazy_type = MyPluginEnumLazyrust-analyzer cargo glib-macros 0.22.6 plugin/MyPluginEnumLazy#::static_typerust-analyzer cargo glib-macros 0.22.6 plugin/impl#[MyPluginEnumLazy][StaticType]static_type().();
380 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(enum_lazy_type.is_validrust-analyzer cargo glib 0.22.5 types/impl#[Type]is_valid().());
381
382 // checks plugin of enums registered as dynamic types is `MyPlugin`.
383 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
384 enum_type.pluginrust-analyzer cargo glib 0.22.5 types/impl#[Type]plugin().().as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().(),
385 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(plugin.upcast_refrust-analyzer cargo glib 0.22.5 object/Cast#upcast_ref().::<glibrust-analyzer cargo glib 0.22.5 crate/::TypePluginrust-analyzer cargo glib 0.22.5 gobject/type_plugin/TypePlugin#>())
386 );
387 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
388 enum_lazy_type.pluginrust-analyzer cargo glib 0.22.5 types/impl#[Type]plugin().().as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().(),
389 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(plugin.upcast_refrust-analyzer cargo glib 0.22.5 object/Cast#upcast_ref().::<glibrust-analyzer cargo glib 0.22.5 crate/::TypePluginrust-analyzer cargo glib 0.22.5 gobject/type_plugin/TypePlugin#>())
390 );
391
392 // simulates the GLib type system to unuse the plugin.
393 TypePluginExtrust-analyzer cargo glib 0.22.5 gobject/type_plugin/TypePluginExt#::unuserust-analyzer cargo glib 0.22.5 gobject/type_plugin/TypePluginExt#unuse().(plugin);
394
395 // checks types of enums registered as dynamic types are still valid.
396 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(MyPluginEnumrust-analyzer cargo glib-macros 0.22.6 plugin/MyPluginEnum#::static_typerust-analyzer cargo glib-macros 0.22.6 plugin/impl#[MyPluginEnum][StaticType]static_type().().is_validrust-analyzer cargo glib 0.22.5 types/impl#[Type]is_valid().());
397 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(MyPluginEnumLazyrust-analyzer cargo glib-macros 0.22.6 plugin/MyPluginEnumLazy#::static_typerust-analyzer cargo glib-macros 0.22.6 plugin/impl#[MyPluginEnumLazy][StaticType]static_type().().is_validrust-analyzer cargo glib 0.22.5 types/impl#[Type]is_valid().());
398
399 // simulates the GLib type system to reuse the plugin.
400 TypePluginExtrust-analyzer cargo glib 0.22.5 gobject/type_plugin/TypePluginExt#::use_rust-analyzer cargo glib 0.22.5 gobject/type_plugin/TypePluginExt#use_().(plugin);
401
402 // checks types of enums registered as dynamic types are still valid.
403 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(MyPluginEnumrust-analyzer cargo glib-macros 0.22.6 plugin/MyPluginEnum#::static_typerust-analyzer cargo glib-macros 0.22.6 plugin/impl#[MyPluginEnum][StaticType]static_type().().is_validrust-analyzer cargo glib 0.22.5 types/impl#[Type]is_valid().());
404 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(MyPluginEnumLazyrust-analyzer cargo glib-macros 0.22.6 plugin/MyPluginEnumLazy#::static_typerust-analyzer cargo glib-macros 0.22.6 plugin/impl#[MyPluginEnumLazy][StaticType]static_type().().is_validrust-analyzer cargo glib 0.22.5 types/impl#[Type]is_valid().());
405
406 // simulates the GLib type system to unuse the plugin.
407 TypePluginExtrust-analyzer cargo glib 0.22.5 gobject/type_plugin/TypePluginExt#::unuserust-analyzer cargo glib 0.22.5 gobject/type_plugin/TypePluginExt#unuse().(plugin);
408 }
409
410 // tests behavior of enums registered as dynamic types within a plugin.
411 fn dynamic_enums_behaviorrust-analyzer cargo glib-macros 0.22.6 plugin/dynamic_enums_behavior().(plugin: &MyPluginrust-analyzer cargo glib-macros 0.22.6 plugin/MyPlugin#) {
412 use glibrust-analyzer cargo glib 0.22.5 crate/::preluderust-analyzer cargo glib 0.22.5 prelude/::*;
413 use glibrust-analyzer cargo glib 0.22.5 crate/::translaterust-analyzer cargo glib 0.22.5 translate/::{FromGlibrust-analyzer cargo glib 0.22.5 translate/FromGlib#, IntoGlibrust-analyzer cargo glib 0.22.5 translate/IntoGlib#};
414
415 // simulates the GLib type system to use the plugin.
416 TypePluginExtrust-analyzer cargo glib 0.22.5 gobject/type_plugin/TypePluginExt#::use_rust-analyzer cargo glib 0.22.5 gobject/type_plugin/TypePluginExt#use_().(plugin);
417
418 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(MyPluginEnumrust-analyzer cargo glib-macros 0.22.6 plugin/MyPluginEnum#::Foorust-analyzer cargo glib-macros 0.22.6 plugin/MyPluginEnum#Foo#.into_glibrust-analyzer cargo glib-macros 0.22.6 plugin/impl#[MyPluginEnum][IntoGlib]into_glib().(), 0);
419 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(MyPluginEnumrust-analyzer cargo glib-macros 0.22.6 plugin/MyPluginEnum#::Barrust-analyzer cargo glib-macros 0.22.6 plugin/MyPluginEnum#Bar#.into_glibrust-analyzer cargo glib-macros 0.22.6 plugin/impl#[MyPluginEnum][IntoGlib]into_glib().(), 1);
420
421 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(unsafe { MyPluginEnumrust-analyzer cargo glib-macros 0.22.6 plugin/MyPluginEnum#::from_glibrust-analyzer cargo glib-macros 0.22.6 plugin/impl#[MyPluginEnum][`FromGlib<i32>`]from_glib().(0) }, MyPluginEnumrust-analyzer cargo glib-macros 0.22.6 plugin/MyPluginEnum#::Foorust-analyzer cargo glib-macros 0.22.6 plugin/MyPluginEnum#Foo#);
422 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(unsafe { MyPluginEnumrust-analyzer cargo glib-macros 0.22.6 plugin/MyPluginEnum#::from_glibrust-analyzer cargo glib-macros 0.22.6 plugin/impl#[MyPluginEnum][`FromGlib<i32>`]from_glib().(1) }, MyPluginEnumrust-analyzer cargo glib-macros 0.22.6 plugin/MyPluginEnum#::Barrust-analyzer cargo glib-macros 0.22.6 plugin/MyPluginEnum#Bar#);
423
424 let t = MyPluginEnumrust-analyzer cargo glib-macros 0.22.6 plugin/MyPluginEnum#::static_typerust-analyzer cargo glib-macros 0.22.6 plugin/impl#[MyPluginEnum][StaticType]static_type().();
425 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(t.is_arust-analyzer cargo glib 0.22.5 types/impl#[Type]is_a().(glibrust-analyzer cargo glib 0.22.5 crate/::Typerust-analyzer cargo glib 0.22.5 types/Type#::ENUMrust-analyzer cargo glib 0.22.5 types/impl#[Type]ENUM.));
426 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(t.namerust-analyzer cargo glib 0.22.5 types/impl#[Type]name().(), "MyPluginEnum");
427
428 let e = glibrust-analyzer cargo glib 0.22.5 crate/::EnumClassrust-analyzer cargo glib 0.22.5 enums/EnumClass#::with_typerust-analyzer cargo glib 0.22.5 enums/impl#[EnumClass]with_type().(t).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("EnumClass::new failed");
429
430 let values = e.valuesrust-analyzer cargo glib 0.22.5 enums/impl#[EnumClass]values().();
431 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(values.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().(), 2);
432 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(values[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()..namerust-analyzer cargo glib 0.22.5 enums/impl#[EnumValue]name().(), "Foo");
433 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(values[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()..nickrust-analyzer cargo glib 0.22.5 enums/impl#[EnumValue]nick().(), "foo");
434 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(values[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().1]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()..namerust-analyzer cargo glib 0.22.5 enums/impl#[EnumValue]name().(), "Bar");
435 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(values[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().1]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()..nickrust-analyzer cargo glib 0.22.5 enums/impl#[EnumValue]nick().(), "bar");
436
437 let v = e.valuerust-analyzer cargo glib 0.22.5 enums/impl#[EnumClass]value().(0).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("EnumClass::get_value(0) failed");
438 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(v.namerust-analyzer cargo glib 0.22.5 enums/impl#[EnumValue]name().(), "Foo");
439 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(v.nickrust-analyzer cargo glib 0.22.5 enums/impl#[EnumValue]nick().(), "foo");
440 let v = e.valuerust-analyzer cargo glib 0.22.5 enums/impl#[EnumClass]value().(1).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("EnumClass::get_value(1) failed");
441 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(v.namerust-analyzer cargo glib 0.22.5 enums/impl#[EnumValue]name().(), "Bar");
442 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(v.nickrust-analyzer cargo glib 0.22.5 enums/impl#[EnumValue]nick().(), "bar");
443 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(e.valuerust-analyzer cargo glib 0.22.5 enums/impl#[EnumClass]value().(2), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
444
445 // within enums registered as dynamic types, values are usables only if
446 // at least one type class ref exists (see `glib::EnumClass`).
447 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
448 MyPluginEnumrust-analyzer cargo glib-macros 0.22.6 plugin/MyPluginEnum#::Foorust-analyzer cargo glib-macros 0.22.6 plugin/MyPluginEnum#Foo#.to_valuerust-analyzer cargo glib-macros 0.22.6 plugin/impl#[MyPluginEnum][ToValue]to_value().().getrust-analyzer cargo glib 0.22.5 value/impl#[Value]get().::<MyPluginEnumrust-analyzer cargo glib-macros 0.22.6 plugin/MyPluginEnum#>(),
449 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(MyPluginEnumrust-analyzer cargo glib-macros 0.22.6 plugin/MyPluginEnum#::Foorust-analyzer cargo glib-macros 0.22.6 plugin/MyPluginEnum#Foo#)
450 );
451 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
452 MyPluginEnumrust-analyzer cargo glib-macros 0.22.6 plugin/MyPluginEnum#::Barrust-analyzer cargo glib-macros 0.22.6 plugin/MyPluginEnum#Bar#.to_valuerust-analyzer cargo glib-macros 0.22.6 plugin/impl#[MyPluginEnum][ToValue]to_value().().getrust-analyzer cargo glib 0.22.5 value/impl#[Value]get().::<MyPluginEnumrust-analyzer cargo glib-macros 0.22.6 plugin/MyPluginEnum#>(),
453 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(MyPluginEnumrust-analyzer cargo glib-macros 0.22.6 plugin/MyPluginEnum#::Barrust-analyzer cargo glib-macros 0.22.6 plugin/MyPluginEnum#Bar#)
454 );
455
456 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(MyPluginEnumLazyrust-analyzer cargo glib-macros 0.22.6 plugin/MyPluginEnumLazy#::Foorust-analyzer cargo glib-macros 0.22.6 plugin/MyPluginEnumLazy#Foo#.into_glibrust-analyzer cargo glib-macros 0.22.6 plugin/impl#[MyPluginEnumLazy][IntoGlib]into_glib().(), 0);
457 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(MyPluginEnumLazyrust-analyzer cargo glib-macros 0.22.6 plugin/MyPluginEnumLazy#::Barrust-analyzer cargo glib-macros 0.22.6 plugin/MyPluginEnumLazy#Bar#.into_glibrust-analyzer cargo glib-macros 0.22.6 plugin/impl#[MyPluginEnumLazy][IntoGlib]into_glib().(), 1);
458
459 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
460 unsafe { MyPluginEnumLazyrust-analyzer cargo glib-macros 0.22.6 plugin/MyPluginEnumLazy#::from_glibrust-analyzer cargo glib-macros 0.22.6 plugin/impl#[MyPluginEnumLazy][`FromGlib<i32>`]from_glib().(0) },
461 MyPluginEnumLazyrust-analyzer cargo glib-macros 0.22.6 plugin/MyPluginEnumLazy#::Foorust-analyzer cargo glib-macros 0.22.6 plugin/MyPluginEnumLazy#Foo#
462 );
463 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
464 unsafe { MyPluginEnumLazyrust-analyzer cargo glib-macros 0.22.6 plugin/MyPluginEnumLazy#::from_glibrust-analyzer cargo glib-macros 0.22.6 plugin/impl#[MyPluginEnumLazy][`FromGlib<i32>`]from_glib().(1) },
465 MyPluginEnumLazyrust-analyzer cargo glib-macros 0.22.6 plugin/MyPluginEnumLazy#::Barrust-analyzer cargo glib-macros 0.22.6 plugin/MyPluginEnumLazy#Bar#
466 );
467
468 let t = MyPluginEnumLazyrust-analyzer cargo glib-macros 0.22.6 plugin/MyPluginEnumLazy#::static_typerust-analyzer cargo glib-macros 0.22.6 plugin/impl#[MyPluginEnumLazy][StaticType]static_type().();
469 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(t.is_arust-analyzer cargo glib 0.22.5 types/impl#[Type]is_a().(glibrust-analyzer cargo glib 0.22.5 crate/::Typerust-analyzer cargo glib 0.22.5 types/Type#::ENUMrust-analyzer cargo glib 0.22.5 types/impl#[Type]ENUM.));
470 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(t.namerust-analyzer cargo glib 0.22.5 types/impl#[Type]name().(), "MyPluginEnumLazy");
471
472 let e = glibrust-analyzer cargo glib 0.22.5 crate/::EnumClassrust-analyzer cargo glib 0.22.5 enums/EnumClass#::with_typerust-analyzer cargo glib 0.22.5 enums/impl#[EnumClass]with_type().(t).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("EnumClass::new failed");
473
474 let values = e.valuesrust-analyzer cargo glib 0.22.5 enums/impl#[EnumClass]values().();
475 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(values.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().(), 2);
476 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(values[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()..namerust-analyzer cargo glib 0.22.5 enums/impl#[EnumValue]name().(), "Foo");
477 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(values[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()..nickrust-analyzer cargo glib 0.22.5 enums/impl#[EnumValue]nick().(), "foo");
478 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(values[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().1]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()..namerust-analyzer cargo glib 0.22.5 enums/impl#[EnumValue]name().(), "Bar");
479 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(values[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().1]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()..nickrust-analyzer cargo glib 0.22.5 enums/impl#[EnumValue]nick().(), "bar");
480
481 let v = e.valuerust-analyzer cargo glib 0.22.5 enums/impl#[EnumClass]value().(0).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("EnumClass::get_value(0) failed");
482 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(v.namerust-analyzer cargo glib 0.22.5 enums/impl#[EnumValue]name().(), "Foo");
483 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(v.nickrust-analyzer cargo glib 0.22.5 enums/impl#[EnumValue]nick().(), "foo");
484 let v = e.valuerust-analyzer cargo glib 0.22.5 enums/impl#[EnumClass]value().(1).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("EnumClass::get_value(1) failed");
485 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(v.namerust-analyzer cargo glib 0.22.5 enums/impl#[EnumValue]name().(), "Bar");
486 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(v.nickrust-analyzer cargo glib 0.22.5 enums/impl#[EnumValue]nick().(), "bar");
487 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(e.valuerust-analyzer cargo glib 0.22.5 enums/impl#[EnumClass]value().(2), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
488
489 // within enums registered as dynamic types, values are usables only if
490 // at least one type class ref exists (see `glib::EnumClass`).
491 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
492 MyPluginEnumLazyrust-analyzer cargo glib-macros 0.22.6 plugin/MyPluginEnumLazy#::Foorust-analyzer cargo glib-macros 0.22.6 plugin/MyPluginEnumLazy#Foo#.to_valuerust-analyzer cargo glib-macros 0.22.6 plugin/impl#[MyPluginEnumLazy][ToValue]to_value().().getrust-analyzer cargo glib 0.22.5 value/impl#[Value]get().::<MyPluginEnumLazyrust-analyzer cargo glib-macros 0.22.6 plugin/MyPluginEnumLazy#>(),
493 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(MyPluginEnumLazyrust-analyzer cargo glib-macros 0.22.6 plugin/MyPluginEnumLazy#::Foorust-analyzer cargo glib-macros 0.22.6 plugin/MyPluginEnumLazy#Foo#)
494 );
495 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
496 MyPluginEnumLazyrust-analyzer cargo glib-macros 0.22.6 plugin/MyPluginEnumLazy#::Barrust-analyzer cargo glib-macros 0.22.6 plugin/MyPluginEnumLazy#Bar#.to_valuerust-analyzer cargo glib-macros 0.22.6 plugin/impl#[MyPluginEnumLazy][ToValue]to_value().().getrust-analyzer cargo glib 0.22.5 value/impl#[Value]get().::<MyPluginEnumLazyrust-analyzer cargo glib-macros 0.22.6 plugin/MyPluginEnumLazy#>(),
497 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(MyPluginEnumLazyrust-analyzer cargo glib-macros 0.22.6 plugin/MyPluginEnumLazy#::Barrust-analyzer cargo glib-macros 0.22.6 plugin/MyPluginEnumLazy#Bar#)
498 );
499
500 // simulates the GLib type system to unuse the plugin.
501 TypePluginExtrust-analyzer cargo glib 0.22.5 gobject/type_plugin/TypePluginExt#::unuserust-analyzer cargo glib 0.22.5 gobject/type_plugin/TypePluginExt#unuse().(plugin);
502 }
503 }