Skip to main content

base_message/
field_value_error.rs

1// Released under the MIT License.
2// Copyright, 2026, by Samuel Williams.
3
4use std::fmt;
5
6/// Why a field value is invalid, as a fixed description. It never includes the value, which may be large or untrusted.
7#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
8pub struct FieldValueError {
9    reason: &'static str,
10}
11
12impl FieldValueError {
13    /// An error with a fixed description, such as `"not a decimal length"`.
14    pub const fn new(reason: &'static str) -> Self {
15        Self { reason }
16    }
17
18    /// The description.
19    pub const fn reason(&self) -> &'static str {
20        self.reason
21    }
22}
23
24impl fmt::Display for FieldValueError {
25    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
26        formatter.write_str(self.reason)
27    }
28}
29
30impl std::error::Error for FieldValueError {}