This page in the guide for rocket has a piece of code as follows:
use rocket::form::Form;
#[derive(FromForm)]
struct Task<'r> {
complete: bool,
r#type: &'r str,
}
#[post("/todo", data = "<task>")]
fn new(task: Form<Task<'_>>) { /* .. */ }
What is the r# in the struct Task?
I know what a raw string literal is in Rust, which begins with r and is immediately bracketed by an arbitrary number of #. It seems however in the above snippet of code there is no closing #.
It allows you to escape the reserved word type and use it as a field of the struct. You can find more about 'raw identifiers' here.
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