pub struct StyledString {
pub s: String,
pub style: Option<Style>,
}
Expand description
An owned string with an optional style annotation.
§Example
let s = format!("Some number: {}", 42);
let s0 = text_style::StyledString::plain(s.clone()).bold();
let s1 = text_style::StyledString::styled(s.clone(), text_style::Style::fg(text_style::AnsiColor::Red.dark()));
let s2 = text_style::StyledString::plain(s.clone()).with(text_style::AnsiColor::Red.dark());
assert_eq!(s1, s2);
Fields§
§s: String
The content of this string.
style: Option<Style>
The style of this string.
Implementations§
Source§impl StyledString
impl StyledString
Sourcepub fn new(s: String, style: Option<Style>) -> StyledString
pub fn new(s: String, style: Option<Style>) -> StyledString
Creates a new styled string from the given string and an optional style.
Sourcepub fn styled(s: String, style: Style) -> StyledString
pub fn styled(s: String, style: Style) -> StyledString
Creates a new styled string from the given string and style.
Sourcepub fn plain(s: String) -> StyledString
pub fn plain(s: String) -> StyledString
Creates a new styled string from the given string and style.
Sourcepub fn strikethrough(self) -> Self
pub fn strikethrough(self) -> Self
Sets the strikethrough effect for this styled string.
Trait Implementations§
Source§impl Clone for StyledString
impl Clone for StyledString
Source§fn clone(&self) -> StyledString
fn clone(&self) -> StyledString
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Debug for StyledString
impl Debug for StyledString
Source§impl Default for StyledString
impl Default for StyledString
Source§fn default() -> StyledString
fn default() -> StyledString
Returns the “default value” for a type. Read more
Source§impl<'a> From<&'a StyledString> for StyledStr<'a>
impl<'a> From<&'a StyledString> for StyledStr<'a>
Source§fn from(s: &'a StyledString) -> StyledStr<'a>
fn from(s: &'a StyledString) -> StyledStr<'a>
Converts to this type from the input type.
Source§impl<'s> From<&'s StyledString> for StyledStr<'s>
impl<'s> From<&'s StyledString> for StyledStr<'s>
Source§fn from(s: &'s StyledString) -> StyledStr<'s>
fn from(s: &'s StyledString) -> StyledStr<'s>
Converts to this type from the input type.
Source§impl<'s> From<&'s StyledString> for StyledString
impl<'s> From<&'s StyledString> for StyledString
Source§fn from(s: &'s StyledString) -> StyledString
fn from(s: &'s StyledString) -> StyledString
Converts to this type from the input type.
Source§impl From<String> for StyledString
impl From<String> for StyledString
Source§fn from(s: String) -> StyledString
fn from(s: String) -> StyledString
Converts to this type from the input type.
Source§impl<'a> From<StyledStr<'a>> for StyledString
impl<'a> From<StyledStr<'a>> for StyledString
Source§fn from(s: StyledStr<'a>) -> StyledString
fn from(s: StyledStr<'a>) -> StyledString
Converts to this type from the input type.
Source§impl<'a> From<StyledString> for ANSIString<'a>
impl<'a> From<StyledString> for ANSIString<'a>
Source§fn from(s: StyledString) -> ANSIString<'a>
fn from(s: StyledString) -> ANSIString<'a>
Converts to this type from the input type.
Source§impl From<StyledString> for StyledString
impl From<StyledString> for StyledString
Source§fn from(s: StyledString) -> StyledString
fn from(s: StyledString) -> StyledString
Converts to this type from the input type.
Source§impl From<StyledString> for StyledContent<String>
impl From<StyledString> for StyledContent<String>
Source§fn from(s: StyledString) -> StyledContent<String>
fn from(s: StyledString) -> StyledContent<String>
Converts to this type from the input type.
Source§impl From<StyledString> for StyledString
impl From<StyledString> for StyledString
Source§fn from(s: StyledString) -> StyledString
fn from(s: StyledString) -> StyledString
Converts to this type from the input type.
Source§impl PartialEq for StyledString
impl PartialEq for StyledString
Source§impl Termion for StyledString
impl Termion for StyledString
Source§fn termion(&self) -> TermionStr<'_>
fn termion(&self) -> TermionStr<'_>
impl StructuralPartialEq for StyledString
Auto Trait Implementations§
impl Freeze for StyledString
impl RefUnwindSafe for StyledString
impl Send for StyledString
impl Sync for StyledString
impl Unpin for StyledString
impl UnwindSafe for StyledString
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more