I forgot to specify the type of a parameter and the error message was as follows:
error: expected one of `:` or `@`, found `)` --> src/main.rs:2:12 | 2 | fn func(arg) | ^ expected one of `:` or `@` here
Which raises the question: what can you do with an @
symbol? I don't remember reading about using the @
symbol for anything. I also did some Googling and couldn't find anything. What does @
do?
An ampersand ( & ) is used with a variable's name while passing its reference instead of its value to a function. The function's signature should also have an ampersand with the type of argument that receives the reference. When a function takes in a reference as a parameter, it is called borrowing.
operator in Rust is used as an error propagation alternative to functions that return Result or Option types.
Please review Appendix B: Operators and Symbols of The Rust Programming Language. In this case, the double colon ( :: ) is the path separator. Paths are comprised of crates, modules, and items. The full path for your example item, updated for 1.0 is: std::usize::BITS.
It dereferences num so you assign to the place in memory it points into (the num variable in main() ) and not to the num variable.
You can use the @
symbol to bind a pattern to a name. As the Rust Reference demonstrates:
let x = 1; match x { e @ 1 ... 5 => println!("got a range element {}", e), _ => println!("anything"), }
Assignments in Rust allow pattern expressions (provided they are complete) and argument lists are no exception. In the specific case of @
, this isn't very useful because you can already name the matched parameter. However, for completeness, here is an example which compiles:
enum MyEnum { TheOnlyCase(u8), } fn my_fn(x @ MyEnum::TheOnlyCase(_): MyEnum) {}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With