1use std::fmt;
2
3use crate::checked_value::impl_checked_value;
4use crate::{
5 LengthPercentageCalculation, NonNegativeLengthPercentage, NonNegativeLengthPercentageValue,
6 serialization::CssWriteTo,
7};
8
9#[derive(Clone, Debug, PartialEq)]
13#[non_exhaustive]
14pub enum GapValue {
15 Normal,
17 LengthPercentage(NonNegativeLengthPercentageValue),
19}
20
21impl From<NonNegativeLengthPercentage> for GapValue {
22 fn from(value: NonNegativeLengthPercentage) -> Self {
23 Self::LengthPercentage(value.into())
24 }
25}
26
27impl From<LengthPercentageCalculation> for GapValue {
28 fn from(value: LengthPercentageCalculation) -> Self {
29 Self::LengthPercentage(value.into())
30 }
31}
32
33impl CssWriteTo for GapValue {
34 fn css_fmt<W: fmt::Write>(&self, w: &mut W) -> fmt::Result {
35 match self {
36 Self::Normal => w.write_str("normal"),
37 Self::LengthPercentage(value) => value.css_fmt(w),
38 }
39 }
40}
41
42#[derive(Clone, Debug, PartialEq)]
44#[non_exhaustive]
45pub enum Gap {
46 One(GapValue),
48 RowColumn(GapValue, GapValue),
50}
51
52impl CssWriteTo for Gap {
53 fn css_fmt<W: fmt::Write>(&self, w: &mut W) -> fmt::Result {
54 match self {
55 Self::One(value) => value.css_fmt(w),
56 Self::RowColumn(row, column) => {
57 row.css_fmt(w)?;
58 w.write_char(' ')?;
59 column.css_fmt(w)
60 }
61 }
62 }
63}
64
65impl_checked_value!(GapValue, Gap);