Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support of flags registered as dynamic types #1271

Merged
merged 3 commits into from Jan 15, 2024

Conversation

fbrouille
Copy link
Contributor

This PR aims to add support of flags registered as dynamic types. See https://docs.gtk.org/gobject/class.TypeModule.html and https://docs.gtk.org/gobject/iface.TypePlugin.html.
The new macro flags_dynamic allows to register the flags that are part of a module or of a plugin (e.g. a shared library on linux). This helper macro generates code that support registration when the plugin (TypePlugin) is used, following the behavior defined in Glib doc. However it is possible to postpone the registration at first use of the flags by explicitly setting the macro attribute lazy_registration = true.

Signed-off-by: fbrouille <fbrouille@users.noreply.github.com>
Signed-off-by: fbrouille <fbrouille@users.noreply.github.com>
…ues to use EnumerationValuesStorages<E>/EnumerationValues<E>

Signed-off-by: fbrouille <fbrouille@users.noreply.github.com>
impl<E: EnumerationValue<E>, const S: usize> EnumerationValuesStorage<E, S> {
// rustdoc-stripper-ignore-next
/// creates a new `EnumerationValuesStorage` with the given values and a final zero value.
pub const fn new<const N: usize>(values: [E; N]) -> Self {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fails compiling if N + 1 != S, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, e.g. if S = N = 3, it fails with:

error[E0308]: mismatched types
...
     = note: expected array `[FlagsValue; 4]`
                found array `[FlagsValue; 3]`

Copy link
Member

@sdroege sdroege left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me otherwise. Thanks!

@pbor @bilelmoussaoui what do you think?

Copy link
Contributor

@pbor pbor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is consistent with all that was already added by @fbrouille for enums etc, so I am good with getting this in

@sdroege sdroege merged commit d08bf24 into gtk-rs:master Jan 15, 2024
48 checks passed
@fbrouille fbrouille deleted the flags_dynamic branch January 15, 2024 12:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants