gir icon indicating copy to clipboard operation
gir copied to clipboard

Manually overriding the codegen for primitive type aliases

Open Ekleog opened this issue 4 years ago • 5 comments

Hello,

In the process of https://github.com/robohouse-delft/aravis-rs/issues/2, it looks like it'd be very useful if gir made it possible to manually implement primitive type aliases. This way, it could be defined as a #[repr(transparent)] struct, that could then gain associated constants, etc.

In particular for https://github.com/robohouse-delft/aravis-rs/issues/2, it'd be useful so as to implement an “open” enum, where the defined values are not the only ones that could be valid, depending on the specific hardware considered — basically, some values have names, but even unnamed values can have meaning.

Do you think it'd be possible to implement in gir?

Cheers, and thank you for gir and gtk-rs :3

Ekleog avatar Jun 07 '20 17:06 Ekleog

Seems type PixelFormat=u32 used only as return value, it seems can overridden with any type that implement FromGlib<u32> See as example: https://github.com/gtk-rs/gtk/blob/master/Gir.toml#L928 https://github.com/gtk-rs/gtk/blob/master/src/auto/dialog.rs#L761

EPashkin avatar Jun 07 '20 18:06 EPashkin

I'm also doing something like that with ClockTime in gstreamer-rs: https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/blob/79b748feb08637729dc9a8485b492cfdb7796478/Gir_Gst.toml#L187

sdroege avatar Jun 07 '20 18:06 sdroege

Ah, interesting. I wasn't aware of the conversion_type config key. But that seems to does the trick. Thanks for the info!

/edit: Note that the type is also used as parameter to Camera::set_pixel_format, so we'll have to implement ToGlib too. But that's no issue :)

de-vri-es avatar Jun 07 '20 22:06 de-vri-es

So nothing needed here or do you still see a possible improvement?

sdroege avatar Jun 08 '20 08:06 sdroege

I suppose it would be nice to have conversion_type documented. But the functionality we needed is already present :)

de-vri-es avatar Jun 08 '20 16:06 de-vri-es