-
Notifications
You must be signed in to change notification settings - Fork 15
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
How to assign (already-declared) variables in a @match
#41
Comments
if you just want to set the markup::define! {
Test() {
@let x = Some(1);
@let y = match x {
Some(n) => n,
None => -1,
};
@y
}
} |
Thanks, but my issue is that I'd like to assign multiple variables. My plan is to pre declare the variables and then assign in the match. If I used a |
I'd propose to simply remove |
My issue is that I would like to replicate the following: let x = Some(1_u32);
let y;
let z;
match x {
Some(n) => {
y = "some";
z = match n {
0 => "zero",
1..=5 => "small",
6..=10 => "medium",
11.. => "big"
};
}
None => {
y = "none";
z = "n/a"
}
} Were I to convert to using tuples, I would have to include |
I have a match that looks like this:
The error I get is
The easiest fix is to simply write
@let _ = match { ... }
, as this “reenables” some Rust syntax that is seemingly not allowed within@match
. But then this leads to a clippy warning, which I can't figure out how to silence because#[allow(clippy::let_unit_value)]
isn't allowed indefine!
. (I could silence the warning at a coarser scope, but don't want to.)I've tried various things, mostly mucking around with moving an
@
sign here and there, and removing thelet
(so just_ = match { ... }
and@_ = match { ... }
, at least one of which feels like it should be legal, but no such luck). I can't figure out how to just assign a variable as a statement inside a@match
. Various other solutions lead tothe trait bound
(): markup::Renderis not satisfied
(i.e., an assignment itself cannot be rendered — fair enough).Does markup support a way to accomplish this (maybe
y @= n
?), or to more generally include arbitrary rust code indefine!
? I'd also reached for${ ... }
as a way to say “the stuff in the{}
is to be run but not rendered” but that didn't work either.Edit: I've wrapped the whole
match
in a@fn
, which gives me access to all the Rust syntax I need, but this seems like overkill.The text was updated successfully, but these errors were encountered: