carllerche / codegen

A Rust library providing a builder API to generate Rust code.
MIT License
251 stars 67 forks source link

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

Closed nbigaouette closed 4 years ago

nbigaouette commented 6 years ago

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 commented 6 years ago

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 https://github.com/rust-lang/rust/issues/42615).

nbigaouette commented 6 years ago

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

LegNeato commented 6 years ago

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

nbigaouette commented 6 years ago

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 commented 6 years ago

Poke again :-D

progval commented 6 years ago

Any news?

kellerkindt commented 6 years ago

Poke? Would be really great if this could get merged

milesgranger commented 5 years ago

@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 commented 4 years ago

Another ping here, can we get this merged?