zbus-old icon indicating copy to clipboard operation
zbus-old copied to clipboard

Controlling the visibility of the struct generated by the #[dbus_proxy] macro

Open zeenix opened this issue 4 years ago • 3 comments
trafficstars

In GitLab by @mominul on Jan 23, 2021, 18:01

Currently the struct and its members generated by the #[dbus_proxy] macro are pub by default. I think it'd be great if we could control the visibility at least of the generated struct. The macro would look for a visibility modifier in the trait declaration.

// It will be a public struct.
#[dbus_proxy(interface = "...")]
pub trait Interface {
    //...
}

// It will be a internal struct.
#[dbus_proxy(interface = "...")]
trait Interface {
    //...
}

// It will be a public in crate struct.
#[dbus_proxy(interface = "...")]
pub(crate) trait Interface {
    //...
}

Thanks!

zeenix avatar Jan 23 '21 17:01 zeenix

Definitely something we should support. Although keep in mind that we only make it pub in the current module, which means you can easily workaround this by putting your macro call in a module:

mod my_private {
   // It will not be public
   #[dbus_proxy(interface = "...")]
   pub trait Interface {
   //...
   }
}

zeenix avatar Jan 23 '21 18:01 zeenix

In GitLab by @mominul on Jan 24, 2021, 17:03

Oops, I thought that would be caught by the unreachable_pub lint, Sorry! :sweat:

zeenix avatar Jan 24 '21 16:01 zeenix

Oops, I thought that would be caught by the unreachable_pub lint, Sorry!

Probably you're right but you can always #[allow(..)] them.

zeenix avatar Jan 24 '21 17:01 zeenix