Styled

Struct Styled 

Source
pub struct Styled<C: Display> { /* private fields */ }
Expand description

A value that associates some content with a specific style.

Implementations§

Source§

impl<C: Display> Styled<C>

Source

pub const fn new(content: C) -> Self

Creates a new Styled<C> value with the given content and empty style.

Source

pub const fn get_content(&self) -> &C

Gets a reference to the enclosed content.

Source

pub const fn with_content<C2: Display>(&self, content: C2) -> Styled<C2>

Returns a new Styled<C2> value with the same style and the given content.

Source

pub fn into_content(self) -> C

Consumes the Styled<C> value and returns the enclosed content.

Source

pub const fn get_style(&self) -> Style

Gets the current style.

Source

pub fn with_style(self, style: Style) -> Styled<C>

Returns a new Styled<C> value with the same content and the given style.

Source

pub fn bold(self) -> Styled<C>

Sets the bold effect.

Source

pub fn faint(self) -> Styled<C>

Sets the faint effect.

Source

pub fn italic(self) -> Styled<C>

Sets the italic effect.

Source

pub fn underline(self) -> Styled<C>

Source

pub fn solid_underline(self) -> Styled<C>

Sets the solid underline effect.

Source

pub fn curly_underline(self) -> Styled<C>

Sets the curly underline effect.

Source

pub fn dotted_underline(self) -> Styled<C>

Sets the dotted underline effect.

Source

pub fn dashed_underline(self) -> Styled<C>

Sets the dashed underline effect.

Sets the blink effect.

Source

pub fn reverse(self) -> Styled<C>

Sets the reverse effect.

Source

pub fn conceal(self) -> Styled<C>

Sets the conceal effect.

Source

pub fn strikethrough(self) -> Styled<C>

Sets the strikethrough effect.

Source

pub fn double_underline(self) -> Styled<C>

Sets the double underline effect.

Source

pub fn overline(self) -> Styled<C>

Sets the overline effect.

Source

pub fn effect(self, effect: impl Into<Effect>) -> Styled<C>

Sets the given effect.

Source

pub fn underline_effect(self, underline_effect: UnderlineEffect) -> Styled<C>

Sets the underline effect.

Source

pub fn fg(self, color: impl Into<Color>) -> Styled<C>

Sets the foreground color.

Source

pub fn bg(self, color: impl Into<Color>) -> Styled<C>

Sets the background color.

Source

pub fn underline_color(self, color: impl Into<Color>) -> Styled<C>

Sets the underline color.

Source

pub fn color(self, targeted_color: impl Into<TargetedColor>) -> Styled<C>

Sets the given color in a target.

Source

pub fn add(self, element: impl StylingElement<Styled<C>>) -> Styled<C>

Adds the given element to the style.

Source

pub fn set_effect(self, effect: impl Into<Effect>, value: bool) -> Self

Sets the given effect to the specified value.

Source

pub fn get_effect(&self, effect: impl Into<Effect>) -> bool

Gets whether the given effect is set.

Source

pub fn get_effects(&self) -> GetEffects

Returns an iterator over the effects that are currently set.

Source

pub fn set_underline_effect( self, underline_effect: Option<UnderlineEffect>, ) -> Self

Sets the underline effect.

Source

pub fn get_underline_effect(&self) -> Option<UnderlineEffect>

Gets the underline effect.

Source

pub fn set_color( self, target: ColorTarget, color: Option<impl Into<Color>>, ) -> Self

Sets the color for the given color target.

To clear the color for some color target, the color type must be specified in the None value. To help with that, the Color::none() method can be used:

styled.set_color(ColorTarget::Foreground, None::<Color>);
// or
styled.set_color(ColorTarget::Foreground, Color::none());
Source

pub fn get_color(&self, target: ColorTarget) -> Option<Color>

Gets the color for the given color target.

Source

pub fn set<A: StylingAttribute<Self>>(self, attr: A, value: A::Value) -> Self

Sets the given attribute to the specified value.

Source

pub fn get<A: StylingAttribute<Self>>(&self, attr: A) -> A::Value

Gets the value of the given attribute.

Source

pub fn remove<A: StylingAttribute<Self>>(self, attr: A) -> Self

Clears the given attribute.

Trait Implementations§

Source§

impl<C: Clone + Display> Clone for Styled<C>

Source§

fn clone(&self) -> Styled<C>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<C: Debug + Display> Debug for Styled<C>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<C: Default + Display> Default for Styled<C>

Source§

fn default() -> Styled<C>

Returns the “default value” for a type. Read more
Source§

impl<C: Display> Display for Styled<C>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<C: Hash + Display> Hash for Styled<C>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<C: PartialEq + Display> PartialEq for Styled<C>

Source§

fn eq(&self, other: &Styled<C>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<C: Display> StylingAttribute<Styled<C>> for ColorTarget

Source§

type Value = Option<Color>

The type of value associated with this attribute.
Source§

fn set_in(self, composed_styling: Styled<C>, value: Self::Value) -> Styled<C>

Sets this attribute in the given parameter, returning it updated.
Source§

fn get_from(self, composed_styling: &Styled<C>) -> Self::Value

Gets the value of this attribute from the given parameter.
Source§

impl<C: Display> StylingAttribute<Styled<C>> for Effect

Source§

type Value = bool

The type of value associated with this attribute.
Source§

fn set_in(self, composed_styling: Styled<C>, value: Self::Value) -> Styled<C>

Sets this attribute in the given parameter, returning it updated.
Source§

fn get_from(self, composed_styling: &Styled<C>) -> Self::Value

Gets the value of this attribute from the given parameter.
Source§

impl<C: Display> StylingAttribute<Styled<C>> for UnderlineEffect

Source§

type Value = bool

The type of value associated with this attribute.
Source§

fn set_in(self, composed_styling: Styled<C>, value: Self::Value) -> Styled<C>

Sets this attribute in the given parameter, returning it updated.
Source§

fn get_from(self, composed_styling: &Styled<C>) -> Self::Value

Gets the value of this attribute from the given parameter.
Source§

impl<C: Display> StylingAttribute<Styled<C>> for UnderlineStyle

Source§

type Value = Option<UnderlineEffect>

The type of value associated with this attribute.
Source§

fn set_in(self, composed_styling: Styled<C>, value: Self::Value) -> Styled<C>

Sets this attribute in the given parameter, returning it updated.
Source§

fn get_from(self, composed_styling: &Styled<C>) -> Self::Value

Gets the value of this attribute from the given parameter.
Source§

impl<C: Display> StylingElement<Styled<C>> for BasicColor

Source§

fn add_to(self, composed_styling: Styled<C>) -> Styled<C>

Adds this element to the given parameter, returning it updated.
Source§

impl<C: Display> StylingElement<Styled<C>> for Color

Source§

fn add_to(self, composed_styling: Styled<C>) -> Styled<C>

Adds this element to the given parameter, returning it updated.
Source§

impl<C: Display> StylingElement<Styled<C>> for Effect

Source§

fn add_to(self, composed_styling: Styled<C>) -> Styled<C>

Adds this element to the given parameter, returning it updated.
Source§

impl<C: Display> StylingElement<Styled<C>> for IndexedColor

Source§

fn add_to(self, composed_styling: Styled<C>) -> Styled<C>

Adds this element to the given parameter, returning it updated.
Source§

impl<C: Display> StylingElement<Styled<C>> for RGBColor

Source§

fn add_to(self, composed_styling: Styled<C>) -> Styled<C>

Adds this element to the given parameter, returning it updated.
Source§

impl<C: Display> StylingElement<Styled<C>> for SimpleColor

Source§

fn add_to(self, composed_styling: Styled<C>) -> Styled<C>

Adds this element to the given parameter, returning it updated.
Source§

impl<C: Display> StylingElement<Styled<C>> for TargetedColor

Source§

fn add_to(self, composed_styling: Styled<C>) -> Styled<C>

Adds this element to the given parameter, returning it updated.
Source§

impl<C: Display> StylingElement<Styled<C>> for UnderlineEffect

Source§

fn add_to(self, composed_styling: Styled<C>) -> Styled<C>

Adds this element to the given parameter, returning it updated.
Source§

impl<C: Copy + Display> Copy for Styled<C>

Source§

impl<C: Eq + Display> Eq for Styled<C>

Source§

impl<C: Display> StructuralPartialEq for Styled<C>

Auto Trait Implementations§

§

impl<C> Freeze for Styled<C>
where C: Freeze,

§

impl<C> RefUnwindSafe for Styled<C>
where C: RefUnwindSafe,

§

impl<C> Send for Styled<C>
where C: Send,

§

impl<C> Sync for Styled<C>
where C: Sync,

§

impl<C> Unpin for Styled<C>
where C: Unpin,

§

impl<C> UnwindSafe for Styled<C>
where C: UnwindSafe,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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<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.