svd_parser/
writeconstraint.rs

1use super::*;
2use crate::svd::{WriteConstraint, WriteConstraintRange};
3
4impl Parse for WriteConstraint {
5    type Object = Self;
6    type Error = SVDErrorAt;
7    type Config = Config;
8
9    fn parse(tree: &Node, _config: &Self::Config) -> Result<Self, Self::Error> {
10        let child = tree.first_element_child().unwrap();
11        if child.next_sibling_element().is_some() {
12            return Err(SVDError::MoreThanOneWriteConstraint.at(tree.id()));
13        }
14        let field = child.tag_name().name();
15        // Write constraint can only be one of the following
16        match field {
17            "writeAsRead" => tree.get_child_bool(field).map(WriteConstraint::WriteAsRead),
18            "useEnumeratedValues" => tree
19                .get_child_bool(field)
20                .map(WriteConstraint::UseEnumeratedValues),
21            "range" => WriteConstraintRange::parse(&tree.get_child_elem(field)?, &())
22                .map(WriteConstraint::Range),
23            _ => Err(SVDError::UnknownWriteConstraint.at(tree.id())),
24        }
25    }
26}
27
28impl Parse for WriteConstraintRange {
29    type Object = Self;
30    type Error = SVDErrorAt;
31    type Config = ();
32
33    fn parse(tree: &Node, _config: &Self::Config) -> Result<Self, Self::Error> {
34        Ok(Self {
35            min: tree.get_child_u64("minimum")?,
36            max: tree.get_child_u64("maximum")?,
37        })
38    }
39}