nextcloud_dav/xml/
missing.rs1use std::error::Error;
4use std::fmt;
5
6#[derive(Clone, Debug, PartialEq, Eq)]
11pub struct MissingElement {
12 name: String,
13}
14
15impl MissingElement {
16 pub fn new(name: &str) -> Self {
18 Self {
19 name: name.to_owned(),
20 }
21 }
22
23 pub fn name(&self) -> &str {
25 &self.name
26 }
27}
28
29impl fmt::Display for MissingElement {
30 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
31 write!(f, "missing element `{}`", self.name)
32 }
33}
34
35impl Error for MissingElement {}
36
37#[cfg(test)]
38mod tests {
39 use std::error::Error;
40
41 use super::MissingElement;
42
43 #[test]
44 fn names_the_element_it_reports() {
45 assert_eq!(MissingElement::new("d:href").name(), "d:href");
46 assert!(MissingElement::new("d:href").to_string().contains("d:href"));
47 }
48
49 #[test]
50 fn is_a_standard_error_usable_as_a_source() {
51 let error: Box<dyn Error + Send + Sync> = Box::new(MissingElement::new("d:multistatus"));
52 assert!(error.to_string().contains("d:multistatus"));
53 }
54}