Comments (5)
@leordev: I would expect that on something like #[builder(each = "arg")] args: Vec<String>
, if .arg(...)
is called 2 times then args
gets built as a vector containing 2 elements; if .arg(...)
is called 0 times then args
gets built as a vector containing 0 elements.
from proc-macro-workshop.
This sounds like a bug in your implementation of the macro? The invocation looks like it should work to me. There is only one env field.
proc-macro-workshop/builder/tests/07-repeated-field.rs
Lines 30 to 38 in 6457670
from proc-macro-workshop.
I think the test expectations could be better documented. When the "each" name is the same as the field name (as is the case with "env" here), it's not possible to generate both a one-at-a-time setter AND an all-at-once setter.
The correct result could be any of the following:
- Don't emit an all-at-once setter function if the one-at-a-time function is requested
- Emit both functions unless there's a name collision, in which case emit only the one-at-a-time fn.
- Emit both functions unless there's a name collision, in which case emit only the all-at-once fn.
- Throw a compiler error if there's a name collision.
If you meant for the name collision to be allowed, then (4) is no good. (3) seems at odds with the programmer's attempt to add something. (1) is maybe too limiting, and (2) seems like a weird side-effect-at-a-distance ("I added B, why did A go away?").
I think @jonhoo found this confusing during his stream also; he went with (2).
from proc-macro-workshop.
Ah, makes sense. I think I had 1 in mind in the reference implementation but 2 would be fine too. I would accept a PR to clarify this in the test case. Thanks!
from proc-macro-workshop.
@dtolnay thank you very much for this amazing workshop! Great job and it's being totally amazing for me!
Aside from the above clarification, I think there's still a bug or I didn't implement as desired since past exercises. The builder is called like this:
let command = Command::builder()
.executable("cargo".to_owned())
.arg("build".to_owned())
.arg("--release".to_owned())
.build()
.unwrap();
We are not calling the builder method to instantiate env
at any moment. So my macro is throwing field "env" is missing
since we are attempting to build()
and env is not an optional field - which I believe is behaving correctly. Did I miss anything?
from proc-macro-workshop.
Related Issues (20)
- Lesson 3
- Compile fail on newer version of syn and quote on derive_builder unrecognize attribute test HOT 1
- Why span in `compile_error!` error message include the ending `;` ? HOT 2
- Update projects and tests to 2021 edition HOT 1
- What to do? HOT 3
- Help with Cargo Expand? HOT 2
- links to industrial implementations HOT 1
- Unused code warning in sorted 04 HOT 2
- Full path in compiler error for bitfield 04 HOT 2
- Nothing is implemented HOT 1
- [Help] How to parsing multi recursive proc macros ? HOT 1
- Seq05 would break multiple other tests. HOT 3
- The dependencies in most of the Cargo.tomls are still `# TODO` HOT 1
- What is best way to print whole path HOT 1
- Reference implementation of bitfield HOT 1
- Sorted: Tests for sorted match expressions do not catch if you always compare to the first arm
- em.i konw three marco ,but still don't konw how to do
- The build function in Builder derive macro should take ownership HOT 1
- Getting the correct span for multi-segment Path HOT 1
- seq test case 03 fail HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from proc-macro-workshop.