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

Issue #3 and #4: Add field documentation and annotation #6

Conversation

nbigaouette
Copy link
Contributor

@nbigaouette nbigaouette commented Jan 6, 2018

This PR adds two fields to the Field struct to set a struct field's documentation and annotation.

The Field type must be pub to be created outside of the crate.

A Struct::push_field() function is added to add the manually created field to the struct.

I also split Fields::named() into named() and push_named() (see 6093af4) to be able to reuse the latter.

This PR is a work in progress. I haven't added the modification to tuple fields since their content is a different type (Type instead of Field). I'd like to make sure this is a proper path before continuing. Maybe the doc and annotation could go inside the Type instead?

Should close #3 and #4.

@nbigaouette
Copy link
Contributor Author

I tried to move the documentation and annotation fields toType.

While it seems possible to go down that route, it might not be as useful as I though. For example rustdoc will not build doc for tuple struct fields (see rust-lang/rust#42615).

@nbigaouette nbigaouette force-pushed the issue-3-and-4-field-documentation-annotation branch from de0d171 to 3e44fb6 Compare January 7, 2018 00:28
Copy link
Owner

@carllerche carllerche left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Looks pretty good. Some minor requests inline.

src/lib.rs Outdated
}

/// Set field's documentation.
pub fn with_documentation(&mut self, documentation: &str) -> &mut Self {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind naming this doc to match the other functions? If you want, we can bikeshed naming patterns in a separate issue.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure! Done in 2d8d4b0.

src/lib.rs Outdated
}

/// Set field's annotation.
pub fn with_annotation(&mut self, annotation: &str) -> &mut Self {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you name this annotation? I'm avoiding with_ prefixes.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 5aafce7.

src/lib.rs Outdated
}
_ => panic!("field list is named"),
}
};
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that this semicolon is needed.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hum! interesting. I though the match would return... Fixed in 95b6673.

Copy link
Owner

@carllerche carllerche left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks 👍, some more thoughts inline.

src/lib.rs Outdated
documentation: String,

/// Field annotation
annotation: String,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this probably should be a Vec<String> to support adding multiple annotations. In this case, the annotation builder function would push a new string.

src/lib.rs Outdated
/// Field name
name: String,

/// Field type
ty: Type,

/// Field documentation
documentation: String,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Documentation strings are tricky. Reading the diff, it looks like only a single doc string line is supported. I'm not sure what the best option would be to support multi lines. Either "\n" could be detected in the documentation string and then it all gets formatted, or documentation could be a Vec<String>.

Thoughts"

Copy link

@LegNeato LegNeato Apr 26, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about different functions? Have doc() take a Vec<String> to stay the same as annotation() and add something like doc_with_newlines() which takes a String.

@nbigaouette
Copy link
Contributor Author

Yes, using a Vec<String> makes sense for documentation and annotation. I'll change those.

@LegNeato
Copy link

@nbigaouette ping. Any chance we can get this landed?

@nbigaouette
Copy link
Contributor Author

nbigaouette commented Apr 20, 2018

Wow, that slipped my mind, sorry! :D

I've replaced the Field.annotation to a Vec<String> for multi-line annotation in 6e17dc2.

I guess something similar could be done for the Field.documentation?

@LegNeato LegNeato mentioned this pull request Apr 27, 2018
@LegNeato
Copy link

LegNeato commented Jun 1, 2018

Poke again :-D

@progval
Copy link

progval commented Jul 5, 2018

Any news?

@kellerkindt
Copy link

Poke? Would be really great if this could get merged

}

/// Set field's annotation.
pub fn annotation(&mut self, annotation: Vec<&str>) -> &mut Self {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe annotation(&mut self, annotation: &str) like import(&mut self, path: &str, ty: &str)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I follow. Do you mean using a &str instead of a Vec<&str> for the annotation() method?

It was changed to use a Vec in 6e17dc2 to support multiple lines.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant a method to add one annotation line per call, like you do for import(...) - each call results in a new import - instead of passing the whole Vec with all lines :)

}

/// Set field's documentation.
pub fn doc(&mut self, documentation: Vec<&str>) -> &mut Self {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe doc(&mut self, documentation: &str) like import(&mut self, path: &str, ty: &str)?

@milesgranger
Copy link

@carllerche Would have been awesome to have this in, as I was going to create an issue.

I really like this lib, but if it's abandoned, a short note on the README would be handy.

@ocrickard
Copy link

Another ping here, can we get this merged?

@andrewleverette andrewleverette dismissed carllerche’s stale review May 9, 2020 10:24

Requested change has been made

@andrewleverette andrewleverette merged commit d94b5ea into carllerche:master May 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fields annotations?
9 participants