Expand description
Declarative, limited parsing of web request content, such as forms, without I/O.
Applications declare the content they accept with #[derive(Content)], with limits on every field, array, and upload, so that a body is never parsed without knowing its limits. ContentParser is fed bytes as they arrive and refuses whatever the declaration does not accept as early as the bytes allow: a name the declaration does not accept before its content is read, and any limit as soon as it is exceeded, with a fatal ContentError. Uploads are reported as events for the caller to store, and the other fields are converted strictly, with every Violation returned together when parsing finishes. The crate does no I/O.
multipart/form-data is parsed with base-web-multipart, and application/x-www-form-urlencoded with base-web-url, whose bracket paths name the fields of both. The Getting Started guide covers declarations, limits, uploads, and errors.
Structs§
- Accepted
- Content that parsed and satisfied its declaration.
- Content
Error - Why content could not be parsed at all, with the offset in the body where the parser found it.
- Content
Parsed - What one call to
ContentParser::parsefound, with the number of input bytes it consumed. - Content
Parser - A sans-I/O parser for a request’s content, into the struct
Tdeclares, fed bytes as they arrive. - Field
Path - The path to a field: the declared names and array indices that lead to it.
- Field
Value Error - Why a field’s text could not be converted to its type. It carries no detail, since the text may be a password or personal data that must not reach logs.
- Rejected
- Content that was refused, with every handle the caller gave the parser, so that provisional uploads can be removed.
- Upload
- A file a form submitted, with the caller’s handle for where its content was stored.
- Upload
Head - An upload that begins: the field it is for, and what the client declared about it, which must not be trusted.
- Violation
- A declared field that arrived but cannot be accepted, or a required one that did not arrive.
Enums§
- Content
Error Kind - The kind of
ContentError. - Content
Event - One step through a body, for the caller to act on. It is exhaustive, so that a caller can match it without a wildcard; adding an event is a breaking change.
- Content
Format - A format of request content this crate parses, chosen by the request’s media type.
- Field
Path Segment - One step of a
FieldPath. - Parameter
Rules - The rules for a
Content-Dispositionfield’s extended parameters, such asfilename*, when reading its name or filename. Forms and other MIME parts follow different RFCs, so a disposition does not choose for you. - Rejection
- Why content was refused: the two kinds of failure
design/errors.mddefines. It is exhaustive, so that an application can match it without a wildcard; adding a kind is a breaking change. - Violation
Code - What is wrong with a field, as a
Violationreports it.
Traits§
- Content
- Content an application declares that it accepts, with limits on everything in it. Derive it with
#[derive(Content)]on a struct with named fields; it must not be implemented by hand, since what the derive implements is not public API. - Content
Handles - A declaration whose uploads hold handles of type
H: any declaration without uploads, for everyH, and one whose uploads areUpload<H>. It is implemented for every such declaration, so that generic code can name whatContentParserparses. - Field
Value - A field’s value converted from its submitted text, the conversion trait for scalar fields.
Derive Macros§
- Content
- Derive a declaration of the content a struct accepts, from its named fields.
- Field
Value - Derive the conversion of an enumeration from a field’s text: the exact, case-sensitive spelling of each variant.