1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
//! `strict_builder!` — makes a generated builder's `build()` the place conformance is enforced.
//!
//! # The rule this implements
//!
//! > Parse permissively, validate explicitly, **construct strictly**.
//!
//! Deserialisation accepts what a peer sent. [`Validate::validate`](super::Validate::validate)
//! reports what is wrong with it. But an object *this crate builds* should never be out of spec in
//! the first place — a partner should not be able to publish a 60-character city name to the
//! roaming network by accident and only find out when Hubject rejects the push, hours later, for
//! the whole batch.
//!
//! Field-level types stay permissive so a builder can take a `&str` (see [`Text`](super::Text)),
//! and the check happens once, on the finished object:
//!
//! * `build()` validates and returns `Result<T, Violations>`.
//! * `build_unchecked()` skips the check, for tests and for re-emitting a peer's payload as it
//! arrived.
//!
//! The name of the second one is the documentation.
/// Gives a `bon`-generated builder a validating `build()` alongside its `build_unchecked()`.
///
/// The type must carry `#[builder(finish_fn = build_unchecked)]`. Arguments are the type, its
/// generated builder, and the generated state module — `bon` derives all three names from the
/// type, but Rust macros cannot concatenate identifiers, so they are spelled out.
pub use strict_builder;