BoxElement

Struct BoxElement 

Source
pub struct BoxElement<'s> { /* private fields */ }
Expand description

An element with its type erased.

This type can be used to return multiple kinds of elements from a function.

§Example

use line_ui::element::{BoxElement, IntoElement};
use line_ui::{Color, Style};

fn foo(value: bool) -> BoxElement<'static> {
    if value {
        "some fancy text"
            .fixed_width(20)
            .styled(Style::fg(Color::RED) + Style::INVERT)
            .boxed()
    } else {
        "just some text".boxed()
    }
}

Implementations§

Source§

impl<'s> BoxElement<'s>

Source

pub fn new<E: Element<'s>>(inner: E) -> Self

Boxes the provided element.

Trait Implementations§

Source§

impl<'s> Element<'s> for BoxElement<'s>

Source§

fn width(&self) -> usize

The width of the element, in columns.
Source§

fn render(&self) -> impl DoubleEndedIterator<Item = RenderChunk<'s>>

Renders the element into a sequence of chunks.

Auto Trait Implementations§

§

impl<'s> Freeze for BoxElement<'s>

§

impl<'s> RefUnwindSafe for BoxElement<'s>

§

impl<'s> Send for BoxElement<'s>

§

impl<'s> Sync for BoxElement<'s>

§

impl<'s> Unpin for BoxElement<'s>

§

impl<'s> UnwindSafe for BoxElement<'s>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<'s, E> IntoElement<'s> for E
where E: Element<'s>,

Source§

type ElementType = E

The element type to be converted into.
Source§

fn into_element(self) -> <E as IntoElement<'s>>::ElementType

Converts this type into an Element.
Source§

fn fixed_width(self, width: usize) -> FixedWidth<Self::ElementType>

Convenience function to wrap this element in a FixedWidth.
Source§

fn styled(self, style: Style) -> Styled<Self::ElementType>

Convenience function to wrap this element in a Styled.
Source§

fn boxed(self) -> BoxElement<'s>

Convenience function to box this element.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.