gtk-rs-core icon indicating copy to clipboard operation
gtk-rs-core copied to clipboard

Bindings for GVariantBuilder

Open zeenix opened this issue 5 years ago • 6 comments

We'll have a way to create and convert to/from Variants after gtk-rs/glib#651 is merged. However, since Variant is supposed to be non-mutable, bindings for GVariantBuilder will be very useful to have.

zeenix avatar Sep 02 '20 18:09 zeenix

The requirements of the g_variant_builder_end() API will be a bit annoying to implement.

sdroege avatar Sep 07 '20 07:09 sdroege

Maybe could implement most of it on the Rust side to enforce those constraints (possibly even in the type system), and only for actually building (parts of) call into the GLib API.

sdroege avatar Sep 07 '20 15:09 sdroege

The requirements of the g_variant_builder_end() API will be a bit annoying to implement.

How so?

It is not permissible to use builder in any way after this call

That's easy with binding for g_variant_builder_end() take self instead of &mut self, no?

It is an error to call this function in any way that would create an inconsistent value to be constructed

That's a bit tough but either we can duplicate the checks in the C function or we just let the user shoot themselves in the foot (they're using C API after all) and document it?

zeenix avatar Sep 07 '20 16:09 zeenix

That's easy with binding for g_variant_builder_end() take self instead of &mut self, no?

It's refcounted, so that's not enough :)

That's a bit tough but either we can duplicate the checks in the C function or we just let the user shoot themselves in the foot (they're using C API after all) and document it?

Duplicating the checks, yes. Ideally we'd prevent that statically at compile time

Not having the checks is not acceptable though, otherwise it would have to be unsafe functions.

sdroege avatar Sep 07 '20 16:09 sdroege

That's easy with binding for g_variant_builder_end() take self instead of &mut self, no?

It's refcounted, so that's not enough :)

But the Rust wrapper struct we'll expose won't be.

That's a bit tough but either we can duplicate the checks in the C function or we just let the user shoot themselves in the foot (they're using C API after all) and document it?

Duplicating the checks, yes. Ideally we'd prevent that statically at compile time

Not having the checks is not acceptable though, otherwise it would have to be unsafe functions.

I guess. :(

zeenix avatar Sep 07 '20 19:09 zeenix

But the Rust wrapper struct we'll expose won't be.

That sounds like a good plan

sdroege avatar Sep 07 '20 20:09 sdroege