Skip to content
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

Support custom documentation for setters #13

Closed
mre opened this issue Aug 7, 2016 · 5 comments
Closed

Support custom documentation for setters #13

mre opened this issue Aug 7, 2016 · 5 comments

Comments

@mre
Copy link
Contributor

mre commented Aug 7, 2016

Consider this builder:

custom_derive! {
    #[derive(Debug, Default, Builder)]
    struct Channel {
        //! This is a comment for token
        token: i32,
        special_info: i32
    }
}

It would be great if there was a way to add the comments as documentation for the fields:

//! This is a comment for token
fn token<VALUE: Into<i32>>(mut self, value: VALUE) -> Self {
    self.token = value.into();
    self
}

No clue if that is possible, though. 😄

@killercup
Copy link
Collaborator

killercup commented Aug 7, 2016

This should be possible, /// hi there comments become #[doc="hi there"] attributes.

Would you want to differentiate between comments for the struct field and comments for the setter? (If the field is not public, its docs wouldn't be rendered, so it might be cool to just add them to the setter fn.)

@mre
Copy link
Contributor Author

mre commented Aug 7, 2016

Thanks for the quick response.
Documentation for the setter would be enough for me right now. But a fallback for non-public fields would be totally awesome. Depends on how tricky it is to implement.

@colin-kiegel
Copy link
Owner

@mre thank you very much for your feedback. :-)

A simple solution would be to allow item doc-comments, but to skip over them and use auto-generated documentation for setters. Spontaneously that is what I would try first and then wait and see if there is a big need for something more sophisticated or magic.

@colin-kiegel
Copy link
Owner

Ok, for now we have auto-generated doc-comments (95f3b4b)

/// Set `$field_name`
///
/// auto-generated by [derive_builder](https://crates.io/crates/derive_builder)

Skipping doc-comments (and pub keywords) in the struct definition is a bit more delicate and therefore a pull request #14

I am open for future changes - but I think this is at least an improvement of the current state. I will release now without the pull request. ;-)

@colin-kiegel
Copy link
Owner

implemented and published with v0.2.0 (Changelog)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants