-
-
Notifications
You must be signed in to change notification settings - Fork 95
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
[bug] zbus-xmlgen generates code that fails to compile with a dictionary-like property #1180
Comments
Ah, so it was a bit tricky... This fixes it locally: diff --git a/zvariant/src/into_value.rs b/zvariant/src/into_value.rs
index 1e35b96f..cfffc054 100644
--- a/zvariant/src/into_value.rs
+++ b/zvariant/src/into_value.rs
@@ -84,6 +84,12 @@ impl From<String> for Value<'_> {
}
}
+impl<'a, 'v> From<&'a Value<'v>> for Value<'v> {
+ fn from(v: &'a Value<'v>) -> Value<'v> {
+ v.clone()
+ }
+}
+
impl<'v, 's: 'v, T> From<T> for Value<'v>
where
T: Into<Structure<'s>>,
diff --git a/zvariant/src/value.rs b/zvariant/src/value.rs
index 76e90d20..30fe0e8f 100644
--- a/zvariant/src/value.rs
+++ b/zvariant/src/value.rs
@@ -966,14 +966,6 @@ impl Type for Value<'_> {
const SIGNATURE: &'static Signature = &Signature::Variant;
}
-impl<'a> TryFrom<&Value<'a>> for Value<'a> {
- type Error = crate::Error;
-
- fn try_from(value: &Value<'a>) -> crate::Result<Value<'a>> {
- value.try_clone()
- }
-}
-
impl Clone for Value<'_> {
/// Clone the value.
/// But is of course not ideal... |
Other alternatives which would be better for my use case, I think would be to make the hashmap values owned in the generated code, for properties, so: diff --git a/examples/dbus/wpa_supplicant/p2pdevice.rs b/examples/dbus/wpa_supplicant/p2pdevice.rs
index dfd406f..3512081 100644
--- a/examples/dbus/wpa_supplicant/p2pdevice.rs
+++ b/examples/dbus/wpa_supplicant/p2pdevice.rs
@@ -312,7 +312,7 @@ pub trait P2PDevice {
#[zbus(property, name = "P2PDeviceConfig")]
fn set_p2pdevice_config(
&self,
- value: std::collections::HashMap<&str, &zbus::zvariant::Value<'_>>,
+ value: std::collections::HashMap<&str, zbus::zvariant::Value<'_>>,
) -> zbus::Result<()>;
/// PeerGO property But a bit out of my dbus depth, so not sure whether that'd be more generally desirable. For now I think I'll roll with that tweak, since for my use case it should work just fine. |
Thank you. 🙏
Yes, I believe this is the desirable output. If you could provide a PR for this, that would be great. P.S. Please keep in mind that xmlgen is currently meant to be just a helper tool to get your started easily and in most cases, you'd want to manually adjust the generated code. It needs some love before it should be used as a reusable tool (e.g as part of a build). |
I wrote this as I was thinking about dbus2#1180, but not sure it's worth the complexity. If you think there are some other things that might use it, please go ahead and merge it, otherwise feel free to close :)
So fwiw I thought of that, and fixing this case is trivial, but there are other cases that are a bit trickier I believe. E.g. for slices we currently generate |
I wrote this as I was thinking about dbus2#1180, but not sure it's worth the complexity. If you think there are some other things that might use it, please go ahead and merge it, otherwise feel free to close :)
(First of all, thanks for this crate, looks amazing)
I was poking at wpa_supplicant's dbus functionality: https://w1.fi/wpa_supplicant/devel/dbus.html
I generated a rust file like:
Which generated a
p2pdevice.rs
file like this (among others):Which looks good / believable. I need to remove the default path in order to use it more generally but that's also expected.
However when building it, I get:
I guess a general
From<HashMap<K, V>> for Value<'_>
might be needed? I can comment out / remove the problematic bit, which seems to be:And then use the lower-level
set_property
I suppose. But that is slightly annoying bBelieve it or not, that was one of the setters I was interested in using.If implementing
From<HashMap<...>>
forValue
is the right fix, I can give a shot at fixing it btw :)The text was updated successfully, but these errors were encountered: