Expand description
structpath is a libary which allows parsing and generating url paths in a convenient type safe way.
structpath leverages serde to help parse values into structs.
§Examples
§Basic example
ⓘ
use serde::{Deserialize, Serialize};
use structpath::Schema;
#[derive(Deserialize)]
struct FooParams {
foo_id: u128,
bar: String,
}
const foo_path = "/foo/<foo_id:u128>/bar/<bar>";
// This is a general idea of a web request handler, not important for the demonstration
fn foo_bar(request: Request) -> Response {
let params: FooParams = Schema::path(foo_path).parse(request.path);
}
fn baz(request: Request) -> Response {
let foo_path = Schema::path(foo_path).generate(FooParams{foo_id: foo_id, bar: bar});
Response::Redirect(foo_path)
}
Structs§
- Schema
- Schema hold the schema definition for a particular url path pattern.
- Segment
Value Schema - SegmentValueSchema holds the schema for a particular value segment.
Enums§
- Deserializer
State - Internal state for Deserializer, usually only useful for debugging.
- Path
Schema Parse Error - Error type for parsing Schemas from a String
- Segment
Schema - SegmentSchema is the schema for a particular path segment
- Segment
Type - SegmentType is a basic enum for specifying what type a segment’s value is.
- Segment
Value - SegmentValue holds a parsed value
- Serializer
State - Internal state used by the Serializer, typically only used for debugging.
- Struct
Path Error - General error type for errors when parsing or generating urls
Functions§
- generate_
path - Generate a string url path given parameters and a
Schema
- parse_
path - Parse a particular path using a
Schema