base_web_content/lib.rs
1// Released under the MIT License.
2// Copyright, 2026, by Samuel Williams.
3
4//! Declarative, limited parsing of web request content, such as forms, without I/O.
5//!
6//! Applications declare the content they accept with [`#[derive(Content)]`](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.
7//!
8//! `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](https://github.com/base-rs/base-web-content/blob/main/context/getting-started.md) guide covers declarations, limits, uploads, and errors.
9
10// The derive's generated code names this crate, so that it can be used within the crate's own tests.
11#[cfg(test)]
12extern crate self as base_web_content;
13
14mod accepted;
15mod content;
16mod content_error;
17mod content_event;
18mod content_format;
19mod content_parser;
20mod declaration;
21mod field_path;
22mod field_value;
23mod form;
24mod rejected;
25mod upload;
26mod violation;
27
28#[doc(hidden)]
29#[path = "private.rs"]
30pub mod __private;
31
32pub use accepted::Accepted;
33pub use base_web_content_macros::{Content, FieldValue};
34pub use base_web_multipart::ParameterRules;
35pub use content::{Content, ContentHandles};
36pub use content_error::{ContentError, ContentErrorKind};
37pub use content_event::{ContentEvent, ContentParsed};
38pub use content_format::ContentFormat;
39pub use content_parser::ContentParser;
40pub use field_path::{FieldPath, FieldPathSegment};
41pub use field_value::{FieldValue, FieldValueError};
42pub use rejected::{Rejected, Rejection};
43pub use upload::{Upload, UploadHead};
44pub use violation::{Violation, ViolationCode};
45
46#[cfg(doctest)]
47#[doc = include_str!("../readme.md")]
48struct Readme;
49
50#[cfg(doctest)]
51#[doc = include_str!("../context/getting-started.md")]
52struct GettingStartedGuide;