-
Notifications
You must be signed in to change notification settings - Fork 14
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
[WIP] Implement enum
variants
#255
base: master
Are you sure you want to change the base?
Conversation
4fe184d
to
f62c23a
Compare
faae42b
to
b9f1a5f
Compare
efdb6fc
to
06290b4
Compare
a2e9198
to
33afb4c
Compare
a948a9d
to
aa66f84
Compare
rinja_derive/src/input.rs
Outdated
@@ -271,6 +271,69 @@ impl TemplateInput<'_> { | |||
} | |||
} | |||
|
|||
pub(crate) enum AnyTemplateArgs { | |||
Item(TemplateArgs), |
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.
Might be better to name it Struct
since we don't support unions currently.
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.
Changed.
rinja_derive/src/integration.rs
Outdated
T: Clone, | ||
A: FnMut(&mut S) -> &mut Option<T>, | ||
{ | ||
if let dest @ None = access(dest) { |
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.
It's super weird. What about:
if let dest @ None = access(dest) { | |
if access(dest).is_none() { |
?
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.
It's the same as let dest = access(dest); if dest.is_none() {
in one line. I found it nifty. :) But changed.
So if I understand correctly, when a variant has a Very hypothetical (and in case I understood everything correctly up to this point): isn't it possible to instead handle the variant like we handle our structs. Trying to explain in code: #[template(src = "boo.txt")]
enum Foo {
A,
#[template(src = "I-am-b.txt")]
B(u32, u32),
#[template(src = "not-boo.txt")]
C { a: u32 },
}
impl Render for Foo {
fn render(&self) -> Result<String> {
match self {
// First the variants with the template
B(_0, _1) => {
// this one needs a struct binding :'(
}
C { a } => {
// We can re-use the code for structs where we can say that this is a struct with a field named `a` and tada.
}
}
}
} Not sure if it's a good idea though... That would allow to skip a type creation for one case. But then |
bf0e2ac
to
b5c642d
Compare
Yep, I implemented it this way so that |
5424b18
to
92cb0bd
Compare
Please tell me when it's ready for final review. ;) (also git conflict) |
Resolves #223.