1use std::fmt;
2
3#[derive(Clone)]
4pub struct Size {
5 width: i32,
6 height: i32,
7}
8
9impl Size {
10 pub fn new(width: i32, height: i32) -> Self {
11 let w = if width <= 0 { 1 } else { width };
12 let h = if height <= 0 { 1 } else { height };
13 Size {
14 width: w,
15 height: h,
16 }
17 }
18}
19
20impl fmt::Display for Size {
21 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
22 write!(f, "{}x{}", self.width, self.height)
23 }
24}
25
26impl From<(i32, i32)> for Size {
27 fn from(s: (i32, i32)) -> Self {
28 Size::new(s.0, s.1)
29 }
30}