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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
//! Error types for worker-matcher operations.
//!
//! The crate uses a single sum-type, [`MatchingError`], for every fallible
//! operation, and a [`Result`] alias to keep call-sites concise.
//!
//! The matching engine itself is **infallible**: scoring two workers always
//! produces a [`crate::MatchResult`]. Errors arise from explicit validation
//! steps such as [`crate::Worker::validate`].
//!
//! ## Example
//!
//! ```
//! use worker_matcher::{MatchingError, Worker};
//!
//! let empty = Worker::builder().build();
//! match empty.validate() {
//! Err(MatchingError::MissingField(msg)) => {
//! assert!(msg.contains("required"));
//! }
//! other => panic!("unexpected: {other:?}"),
//! }
//! ```
use Error;
/// Result alias used throughout the crate.
///
/// Equivalent to `std::result::Result<T, MatchingError>`.
///
/// ```
/// use worker_matcher::Result;
/// fn doubled(x: i32) -> Result<i32> { Ok(x * 2) }
/// assert_eq!(doubled(3).unwrap(), 6);
/// ```
pub type Result<T> = Result;
/// Errors that may be returned by worker-matcher operations.
///
/// The matching engine itself is infallible — scoring two workers always
/// produces a [`crate::MatchResult`]. The only fallible operation in the
/// public surface today is [`crate::Worker::validate`], which returns
/// [`MatchingError::MissingField`] when neither a name nor an identifier
/// is populated. Identifier parsers in [`crate::identifiers`] return
/// `Option<String>` (the parser is the source of truth on validity), so
/// they never surface as errors. Configuration builders
/// ([`crate::MatchConfig::default`], `strict`, `lenient`) are infallible.
///
/// The enum is `#[non_exhaustive]` so future fallible code paths can add
/// variants without breaking SemVer for downstream pattern-matches.
///
/// ```
/// use worker_matcher::MatchingError;
///
/// let e = MatchingError::MissingField("nhs_number".into());
/// // `Display` is provided by `thiserror`.
/// assert!(e.to_string().contains("Missing required field"));
/// ```