uuid
only.Expand description
UUID path/query parameter and form value parsing support.
§Enabling
This module is only available when the uuid
feature is enabled. Enable it
in Cargo.toml
as follows:
[dependencies.rocket]
version = "0.5.1"
features = ["uuid"]
§Usage
Uuid
implements FromParam
and FromFormField
(i.e,
FromForm
), allowing UUID values to be accepted
directly in paths, queries, and forms. You can use the Uuid
type directly
as a target of a dynamic parameter:
use rocket::serde::uuid::Uuid;
#[get("/users/<id>")]
fn user(id: Uuid) -> String {
format!("We found: {}", id)
}
You can also use the Uuid
as a form value, including in query strings:
use rocket::serde::uuid::Uuid;
#[get("/user?<id>")]
fn user(id: Uuid) -> String {
format!("User ID: {}", id)
}
Additionally, Uuid
implements UriDisplay<P>
for all P
. As such, route
URIs including Uuid
s can be generated in a type-safe manner:
use rocket::serde::uuid::Uuid;
use rocket::response::Redirect;
#[get("/user/<id>")]
fn user(id: Uuid) -> String {
format!("User ID: {}", id)
}
#[get("/user?<id>")]
fn old_user_path(id: Uuid) -> Redirect {
Redirect::to(uri!(user(id)))
}
§Extra Features
The uuid
crate exposes extra v{n}
features
for generating UUIDs which are not enabled by Rocket. To enable these
features, depend on uuid
directly. The extra functionality can be accessed
via both rocket::serde::uuid::Uuid
or the direct uuid::Uuid
; the types
are one and the same.
[dependencies.uuid]
version = "1"
features = ["v1", "v4"]
Modules§
- Adapters for alternative string formats.
Macros§
- Parse
Uuid
s from string literals at compile time.
Structs§
- A builder for creating a UUID.
- Error returned on
FromParam
orFromFormField
failures. - A Universally Unique Identifier (UUID).
Enums§
- The reserved variants of UUIDs.
- The version of the UUID, denoting the generating algorithm.
Type Aliases§
- A 128-bit (16 byte) buffer containing the UUID.