serde.
Any percent encoded parameters will be automatically decoded. The decoded parameters must be valid UTF-8, otherwise Path will fail and return a 400 Bad Request response.
Type signature
Usage
Single parameter
If the path contains only one parameter, you can omit the tuple:Multiple parameters with tuple
Multiple parameters with struct
Path segment labels will be matched with struct field names:Capturing all parameters
You can useHashMap or Vec to capture all path parameters:
Error handling
PathRejection
Returned when path parameters cannot be deserialized into the target type.
Error kinds
ThePathRejection type contains an ErrorKind enum with detailed error information:
WrongNumberOfParameters- The URI contained a different number of parameters than expectedParseErrorAtKey- Failed to parse a value at a specific key (for structs)ParseErrorAtIndex- Failed to parse a value at a specific index (for tuples)ParseError- Failed to parse a value (for primitives)InvalidUtf8InPathParam- A parameter contained invalid UTF-8 after percent decodingUnsupportedType- Attempted to deserialize into an unsupported typeDeserializeError- Custom deserialization error
Customizing rejections
See the customize-path-rejection example for how to provide custom error responses.Optional path parameters
You can useOption<Path<T>> to allow the same handler to be used in routes with and without parameters:
Percent decoding
Path parameters are automatically percent decoded. For example,%20 becomes a space:
Raw path parameters
For lower-level access without deserialization, useRawPathParams: