maven_rs/settings/
mirrors.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
use derive_builder::Builder;
use serde::{Deserialize, Serialize};

use crate::editor::{
    utils::{
        create_basic_text_element, find_or_create_then_set_text_content, from_element_using_builder,
    },
    ChildOfListElement, ElementConverter, HasElementName, UpdatableElement,
};

#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
pub struct Mirrors {
    #[serde(rename = "mirror")]
    pub mirrors: Vec<Mirror>,
}

#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize, Builder)]
#[serde(rename_all = "camelCase")]
pub struct Mirror {
    pub id: String,
    pub name: String,
    pub url: String,
    pub mirror_of: String,
}
impl HasElementName for Mirror {
    fn element_name() -> &'static str {
        "mirror"
    }
}

impl ElementConverter for Mirror {
    from_element_using_builder!(
        MirrorBuilder,
        element,
        document,
        "id" => id,
        "name" => name,
        "url" => url,
        "mirrorOf" => mirror_of
    );
    fn into_children(
        self,
        document: &mut edit_xml::Document,
    ) -> Result<Vec<edit_xml::Element>, crate::editor::XMLEditorError> {
        let children = vec![
            create_basic_text_element(document, "id", self.id),
            create_basic_text_element(document, "name", self.name),
            create_basic_text_element(document, "url", self.url),
            create_basic_text_element(document, "mirrorOf", self.mirror_of),
        ];
        Ok(children)
    }
}
impl ChildOfListElement for Mirror {
    fn parent_element_name() -> &'static str {
        "mirrors"
    }
}

impl UpdatableElement for Mirror {
    fn update_element(
        &self,
        element: edit_xml::Element,
        document: &mut edit_xml::Document,
    ) -> Result<(), crate::editor::XMLEditorError> {
        let Mirror {
            name,
            url,
            mirror_of,
            ..
        } = self;
        find_or_create_then_set_text_content(document, element, "name", name);
        find_or_create_then_set_text_content(document, element, "url", url);
        find_or_create_then_set_text_content(document, element, "mirrorOf", mirror_of);
        Ok(())
    }
}