1
use std::ops::Mul;
2

            
3
use crate::{Figure, Size};
4

            
5
impl<T, Unit> Size<T, Unit>
6
where
7
    T: Mul<T, Output = T> + Copy,
8
{
9
    /// Returns the area represented by this size.
10
    pub fn area(&self) -> Figure<T, Unit> {
11
        self.width() * self.height()
12
    }
13
}
14

            
15
impl<T, U> Size<T, U>
16
where
17
    T: Default + Copy,
18
{
19
    /// Returns a new vector with `width`, and `T::default()` for `height`.
20
1
    pub fn from_width(width: impl Into<Figure<T, U>>) -> Self {
21
1
        Self::new(width.into().get(), T::default())
22
1
    }
23

            
24
    /// Returns a new vector with `height`, and `T::default()` for `width`.
25
1
    pub fn from_height(height: impl Into<Figure<T, U>>) -> Self {
26
1
        Self::new(T::default(), height.into().get())
27
1
    }
28
}
29

            
30
1
#[test]
31
1
fn size_from_partial_tests() {
32
1
    assert_eq!(Size::<u32, ()>::from_width(1), Size::new(1, 0));
33
1
    assert_eq!(Size::<u32, ()>::from_height(1), Size::new(0, 1));
34
1
}