Reputation: 83
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 #
.
Upvotes: 4
Views: 1561
Reputation: 136
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.
Upvotes: 6