backblaze_b2_client/util/
is_valid.rs

1use std::{error::Error, fmt::Display};
2
3pub trait IsValid {
4    /// Whether the current object is valid or not
5    fn is_valid(&self) -> Result<(), InvalidValue>;
6}
7
8#[derive(Debug)]
9pub struct InvalidValue {
10    pub object_name: String,
11    pub value_name: String,
12    pub value_as_string: String,
13    pub expected: String,
14}
15
16impl Display for InvalidValue {
17    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
18        write!(
19            f,
20            "Passed {} value is valid, for field {} got [{}] expected [{}].",
21            self.object_name, self.value_name, self.value_as_string, self.expected
22        )
23    }
24}
25
26impl Error for InvalidValue {}