|
|
|
|
|
by VGHN7XDuOXPAzol
351 days ago
|
|
maybe this isn't the question you meant to ask, but: `n` has the same type as the input of the `match` block. In other words, it's a fallback case. (In this case, it's `&str`; the same as `"+"`, `"-"`, etc) If you're wondering how `n.parse().unwrap()` has its type computed, well that part is because type inference is able to look at the definition of `Token::Operand(u32)` and discover that it's `u32`. From my experience: The compiler can do this, as long as the first usage of the unknown-typed-thing gives it a type.
If the first usage of it doesn't, then it won't try any harder to infer the type and it won't compile unless you add your own annotations on. |
|
[1]: https://doc.rust-lang.org/std/primitive.str.html#method.pars... [2]: https://doc.rust-lang.org/std/str/trait.FromStr.html