Skip to content

Commit

Permalink
🐛 zx: Fix declaring proxies for writable properties
Browse files Browse the repository at this point in the history
The `#[dbus_proxy(property)]` attribute needs to be present also at the
`set_foo` function, otherwise the proxy will call a `SetFoo` method instead of
`Set`ting the `Foo` property.

Example:
agama-project/agama#712
  • Loading branch information
mvidner committed Aug 23, 2023
1 parent 4169a3f commit eccbb48
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
13 changes: 7 additions & 6 deletions zbus_xmlgen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,21 +65,22 @@ impl<'i> Display for GenTrait<'i> {
props.sort_by(|a, b| a.name().partial_cmp(&b.name()).unwrap());
for p in props {
let name = to_identifier(&to_snakecase(p.name().as_str()));
let fn_attribute = if pascal_case(&name) != p.name().as_str() {
format!(" #[dbus_proxy(property, name = \"{}\")]", p.name())
} else {
" #[dbus_proxy(property)]".to_string()
};

writeln!(f)?;
writeln!(f, " /// {} property", p.name())?;
if pascal_case(&name) != p.name().as_str() {
writeln!(f, " #[dbus_proxy(property, name = \"{}\")]", p.name())?;
} else {
writeln!(f, " #[dbus_proxy(property)]")?;
}

if p.access().read() {
writeln!(f, "{}", fn_attribute)?;
let output = to_rust_type(p.ty(), false, false);
writeln!(f, " fn {name}(&self) -> zbus::Result<{output}>;",)?;
}

if p.access().write() {
writeln!(f, "{}", fn_attribute)?;
let input = to_rust_type(p.ty(), true, true);
writeln!(
f,
Expand Down
1 change: 1 addition & 0 deletions zbus_xmlgen/tests/data/sample_object0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ trait SampleInterface0 {
/// Bar property
#[dbus_proxy(property)]
fn bar(&self) -> zbus::Result<u8>;
#[dbus_proxy(property)]
fn set_bar(&self, value: u8) -> zbus::Result<()>;
}

0 comments on commit eccbb48

Please sign in to comment.