-
-
Notifications
You must be signed in to change notification settings - Fork 117
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
[FEATURE REQUEST] Properties macro: Document properties better #1236
Comments
I also have the same issue with exposing properties to a public object in a library. Specifically, I had to resort to manually implementing the properties in https://github.com/SeaDve/plotters-gtk4/blob/main/src/paintable.rs to improve the documentation. I'm wondering if the field documentation on the #[derive(glib::Properties)]
#[properties(wrapper_type = Paintable)]
pub struct PaintableImp {
/// The width of the paintable.
#[property(get, set)]
pub(super) width: OnceCell<u32>,
/// The height of the paintable.
#[property(get, set)]
pub(super) height: OnceCell<u32>,
} will generate the following getters: impl Paintable {
/// The width of the paintable.
pub fn width(&self) -> u32 {
...
}
/// The height of the paintable.
pub fn height(&self) -> u32 {
...
}
} Not sure though of a great API to specialize the documentation for the setters. |
Unfortunately I don't think you can make the properties get documented in the wrapper type itself as the Given that docs are one attribute per line, I wonder if you could add a marker attribute to indicate you're switching to the setter and then the rest of the docs could be for the setter. This is probably terrible stylistically but it could probably work. Something like #[derive(glib::Properties)]
#[properties(wrapper_type = MyType)]
pub struct MyTypeImp {
/// The width of the object in my type.
#[setter_doc]
/// Set the width of the object. This has a million side effects
#[property(get, set)]
pub(super) width: RefCell<u32>,
} that then becomes impl MyType {
/// The width of the paintable.
pub width() -> u32 {
...
}
/// Set the width of the object. This has a million side effects
pub set_width(v: u32) {
...
}
} you can of course also have /// The width of the object in my type.
#[setter_doc = "Set the width of the object. This has a million side effects"]
#[property(get, set)]
pub(super) width: RefCell<u32>, so you have It doesn't look like we could abuse the |
While trying to implement this I realised it's more complicated because you can have multiple So to support something with comments for both like /// The name of the author
#[property(name = "author-name", get, set, type = String, member = name)]
/// The author's childhood nickname
#[property(name = "author-nick", get, set, type = String, member = nick)]
author: RefCell<Author>, and get the right right docs for each of |
I'm using cargo docs online for people to work on Loupe and I'm sometimes using it myself.
With using the
Properties
macro the docs got a bit worse. Before, getters also had documentation. Now I have to lookup the field in the struct to see it's documentation.Is it possible to either link to the field in getter/setter docs or do create an overview of all properties for the object or maybe both?
The text was updated successfully, but these errors were encountered: