form_net/hook.rs
1//! Hooks for other crates to take part in a parse. In 0.3 this holds
2//! [`Refusal`], which [`FormError::Refused`](crate::FormError::Refused)
3//! carries; the inspector and sink traits arrive in 0.4.
4
5/// Why an inspector refused the input: the HTTP status it wants and a
6/// stable, machine-readable code for the reason.
7///
8/// [`FormError::status_hint`](crate::FormError::status_hint) returns the
9/// status (400 when it is outside 400 to 599: a refusal is never a success);
10/// [`FormError::code`](crate::FormError::code) returns the code. The code
11/// must never contain input.
12///
13/// # Examples
14///
15/// ```
16/// use form_net::Refusal;
17///
18/// let r = Refusal::new(415, "customs.avatar_not_image");
19/// assert_eq!((r.status, r.code), (415, "customs.avatar_not_image"));
20/// ```
21#[non_exhaustive]
22#[derive(Clone, Copy, Debug, PartialEq, Eq)]
23pub struct Refusal {
24 /// The HTTP status the inspector wants.
25 pub status: u16,
26 /// The inspector's stable code for the reason.
27 pub code: &'static str,
28}
29
30impl Refusal {
31 /// A refusal with this status and code.
32 #[must_use]
33 pub const fn new(status: u16, code: &'static str) -> Refusal {
34 Refusal { status, code }
35 }
36}