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
use super::NodeIdx;
use crate::Attribute;
use std::fmt;

/// Remove attributes that the old node had that the new node doesn't
#[derive(PartialEq)]
pub struct RemoveAttributes<'a, NS, TAG, ATT, VAL, EVENT, MSG> {
    /// the tag of the node to be remove
    /// this is only used for verifying that we are patching the correct node
    pub tag: &'a TAG,
    /// index of the node we are going to patch
    /// relative to the application root node
    pub node_idx: NodeIdx,
    /// the new node_idx of the node we are removing attributes from
    pub new_node_idx: NodeIdx,
    /// attributes that are to be removed from this target node
    pub attrs: Vec<&'a Attribute<NS, ATT, VAL, EVENT, MSG>>,
}

impl<'a, NS, TAG, ATT, VAL, EVENT, MSG>
    RemoveAttributes<'a, NS, TAG, ATT, VAL, EVENT, MSG>
{
    /// Add attributes that the new node has that the old node does not
    /// Note: the attributes is not a reference since attributes of same
    /// name are merged to produce a new unify attribute
    pub fn new(
        tag: &'a TAG,
        node_idx: NodeIdx,
        new_node_idx: NodeIdx,
        attrs: Vec<&'a Attribute<NS, ATT, VAL, EVENT, MSG>>,
    ) -> Self {
        RemoveAttributes {
            tag,
            node_idx,
            new_node_idx,
            attrs,
        }
    }
}

impl<'a, NS, TAG, ATT, VAL, EVENT, MSG> fmt::Debug
    for RemoveAttributes<'a, NS, TAG, ATT, VAL, EVENT, MSG>
where
    NS: fmt::Debug,
    TAG: fmt::Debug,
    ATT: fmt::Debug,
    VAL: fmt::Debug,
{
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        f.debug_struct("RemoveAttributes")
            .field("tag", &self.tag)
            .field("node_idx", &self.node_idx)
            .field("new_node_idx", &self.new_node_idx)
            .field("attrs", &self.attrs)
            .finish()
    }
}