1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
use crate::Element;

pub trait IntoOptionalElement {
    fn into_optional_element(self) -> Option<Element>;
}

pub trait IntoElement {
    fn into_element(self) -> Element;
}

impl<T: IntoElement> IntoOptionalElement for T {
    #[inline]
    fn into_optional_element(self) -> Option<Element> {
        Some(self.into_element())
    }
}

impl IntoElement for Element {
    #[inline]
    fn into_element(self) -> Element {
        self
    }
}

impl<T: IntoOptionalElement> IntoOptionalElement for Option<T> {
    #[inline]
    fn into_optional_element(self) -> Option<Element> {
        self.and_then(IntoOptionalElement::into_optional_element)
    }
}