1use std::fmt;
2
3#[derive(Debug, Default, Clone, Copy, Eq, PartialEq, Hash)]
4#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
5pub struct Margin {
6 pub horizontal: u16,
7 pub vertical: u16,
8}
9
10impl Margin {
11 pub const fn new(horizontal: u16, vertical: u16) -> Self {
12 Self {
13 horizontal,
14 vertical,
15 }
16 }
17}
18
19impl fmt::Display for Margin {
20 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
21 write!(f, "{}x{}", self.horizontal, self.vertical)
22 }
23}
24
25#[cfg(test)]
26mod tests {
27 use super::*;
28
29 #[test]
30 fn margin_to_string() {
31 assert_eq!(Margin::new(1, 2).to_string(), "1x2");
32 }
33
34 #[test]
35 fn margin_new() {
36 assert_eq!(
37 Margin::new(1, 2),
38 Margin {
39 horizontal: 1,
40 vertical: 2
41 }
42 );
43 }
44}