1use crate::element::{Element, FixedWidth, Styled, Text};
6use crate::style::Style;
7
8pub trait IntoElement: Sized {
10 type ElementType: Element;
12
13 fn into_element(self) -> Self::ElementType;
15
16 fn fixed_width(self, width: usize) -> FixedWidth<Self::ElementType> {
18 FixedWidth::new(width, self.into_element())
19 }
20
21 fn with_style(self, style: Style) -> Styled<Self::ElementType> {
23 Styled::new(style, self.into_element())
24 }
25}
26
27impl<E: Element> IntoElement for E {
28 type ElementType = Self;
29
30 fn into_element(self) -> Self::ElementType {
31 self
32 }
33}
34
35impl<'s> IntoElement for &'s str {
36 type ElementType = Text<'s>;
37
38 fn into_element(self) -> Self::ElementType {
39 Text::from(self)
40 }
41}