accessibility_tree/style/values/
generic.rs1use crate::style::errors::PropertyParseError;
2use crate::style::values::Parse;
3use cssparser::Parser;
4
5pub struct FourSides<T> {
6 pub top: T,
7 pub left: T,
8 pub bottom: T,
9 pub right: T,
10}
11
12impl<T> Parse for FourSides<T>
13where
14 T: Parse + Clone,
15{
16 fn parse<'i, 't>(parser: &mut Parser<'i, 't>) -> Result<Self, PropertyParseError<'i>> {
17 let top = T::parse(parser)?;
18
19 let left = if let Ok(left) = parser.r#try(T::parse) {
20 left
21 } else {
22 return Ok(FourSides {
23 top: top.clone(),
24 left: top.clone(),
25 bottom: top.clone(),
26 right: top,
27 });
28 };
29
30 let bottom = if let Ok(bottom) = parser.r#try(T::parse) {
31 bottom
32 } else {
33 return Ok(FourSides {
34 top: top.clone(),
35 left: left.clone(),
36 bottom: top,
37 right: left,
38 });
39 };
40
41 let right = if let Ok(right) = parser.r#try(T::parse) {
42 right
43 } else {
44 return Ok(FourSides {
45 top: top,
46 left: left.clone(),
47 bottom: bottom,
48 right: left,
49 });
50 };
51
52 Ok(FourSides {
53 top,
54 left,
55 bottom,
56 right,
57 })
58 }
59}