Skip to main content

river_data_core/models/
vocabulary.rs

1/// A string that is not one of a closed vocabulary's values.
2///
3/// Carries what was read and what was expected, because the two together are what a caller needs to
4/// correct a stored value or a request field.
5#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
6#[error("'{value}' is not one of: {expected}")]
7pub struct UnknownValue {
8    pub value: String,
9    pub expected: String,
10}
11
12impl UnknownValue {
13    pub(crate) fn new(value: &str, expected: impl Iterator<Item = &'static str>) -> Self {
14        Self {
15            value: value.to_string(),
16            expected: expected.collect::<Vec<_>>().join(", "),
17        }
18    }
19}