Closed ids1024 closed 4 years ago
While FromVariant
allows things like this:
let ret: (HashMap<String, Variant>,) = proxy
.call_sync::<gio::Cancellable>(
"GetManagedObjects",
None,
gio::DBusCallFlags::NONE,
60000,
None,
)
.unwrap()
.get()
.unwrap();
Not sure if it would be strange for Variant
to implement FromVariant
but not ToVariant
.
Or some breaking changes to glib-rs which in some way would involve not having a
impl<T: ToVariant> From<T> for Variant
implementation.
That's what I would suggest. The From
impl doesn't make much sense, that's why there's a separate trait already.
With the new methods and trait implementations provided in https://github.com/gtk-rs/glib/pull/651, it seems like it would be helpful if
Variant
implementedToVariant
andFromVariant
.As a motivating example, consider this snippet trying to set a property with gdbus:
This almost works, except the fact
Variant::new_variant(&value)
returns aVariant
, which doesn't implementToVariant
. It's possible by passing a vector of variants toVariant::new_tuple
, but it would be nice it the somewhat more ergonomic API were available.Unfortunately, implementing
ToVariant
results in a compiler error:I can send a PR implementing
FromVariant
, since that doesn't pose an issue. But I'm not sure there's any way to supportToVariant
onVariant
, without new/unstable functionality in Rustc (specialization, negative trait bounds). Or some breaking changes to glib-rs which in some way would involve not having aimpl<T: ToVariant> From<T> for Variant
implementation.