Skip to main content

langfuse_client_base/models/
parse_enum_error.rs

1/// The error of parsing a string into a generated enum: the string names none of its variants.
2#[derive(Clone, Debug, Eq, PartialEq)]
3pub struct ParseEnumError {
4    type_name: &'static str,
5    value: String,
6}
7
8impl ParseEnumError {
9    pub(crate) fn new(type_name: &'static str, value: &str) -> Self {
10        Self {
11            type_name,
12            value: value.to_owned(),
13        }
14    }
15
16    /// The enum that was parsed into.
17    pub fn type_name(&self) -> &'static str {
18        self.type_name
19    }
20
21    /// The string that was rejected.
22    pub fn value(&self) -> &str {
23        &self.value
24    }
25}
26
27impl std::fmt::Display for ParseEnumError {
28    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
29        write!(
30            f,
31            "invalid value {:?} for enum {}",
32            self.value, self.type_name
33        )
34    }
35}
36
37impl std::error::Error for ParseEnumError {}