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
use crate::style::errors::PropertyParseError;
use crate::style::values::Parse;
use cssparser::Parser;

pub struct FourSides<T> {
    pub top: T,
    pub left: T,
    pub bottom: T,
    pub right: T,
}

impl<T> Parse for FourSides<T>
where
    T: Parse + Clone,
{
    fn parse<'i, 't>(parser: &mut Parser<'i, 't>) -> Result<Self, PropertyParseError<'i>> {
        let top = T::parse(parser)?;

        let left = if let Ok(left) = parser.r#try(T::parse) {
            left
        } else {
            return Ok(FourSides {
                top: top.clone(),
                left: top.clone(),
                bottom: top.clone(),
                right: top,
            });
        };

        let bottom = if let Ok(bottom) = parser.r#try(T::parse) {
            bottom
        } else {
            return Ok(FourSides {
                top: top.clone(),
                left: left.clone(),
                bottom: top,
                right: left,
            });
        };

        let right = if let Ok(right) = parser.r#try(T::parse) {
            right
        } else {
            return Ok(FourSides {
                top: top,
                left: left.clone(),
                bottom: bottom,
                right: left,
            });
        };

        Ok(FourSides {
            top,
            left,
            bottom,
            right,
        })
    }
}