-
Notifications
You must be signed in to change notification settings - Fork 65
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
Issue #3 and #4: Add field documentation and annotation #6
Conversation
I tried to move the 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). |
de0d171
to
3e44fb6
Compare
There was a problem hiding this 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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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"), | ||
} | ||
}; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this 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, |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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"
There was a problem hiding this comment.
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
.
Yes, using a |
@nbigaouette ping. Any chance we can get this landed? |
…ti-line annotation
Wow, that slipped my mind, sorry! :D I've replaced the I guess something similar could be done for the |
Poke again :-D |
…multi-line documentation
Any news? |
Poke? Would be really great if this could get merged |
} | ||
|
||
/// Set field's annotation. | ||
pub fn annotation(&mut self, annotation: Vec<&str>) -> &mut Self { |
There was a problem hiding this comment.
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)
?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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)
?
@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. |
Another ping here, can we get this merged? |
Requested change has been made
This PR adds two fields to the
Field
struct to set a struct field's documentation and annotation.The
Field
type must bepub
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()
intonamed()
andpush_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 ofField
). I'd like to make sure this is a proper path before continuing. Maybe the doc and annotation could go inside theType
instead?Should close #3 and #4.