pub struct StyledStr<'a> {
pub s: &'a str,
pub style: Option<Style>,
}
Expand description
A borrowed string with an optional style annotation.
§Example
let s = text_style::StyledStr::plain("test").bold();
let s1 = text_style::StyledStr::styled("test", text_style::Style::fg(text_style::AnsiColor::Red.dark()));
let s2 = text_style::StyledStr::plain("test").with(text_style::AnsiColor::Red.dark());
assert_eq!(s1, s2);
Fields§
§s: &'a str
The content of this string.
style: Option<Style>
The style of this string.
Implementations§
Source§impl<'a> StyledStr<'a>
impl<'a> StyledStr<'a>
Sourcepub fn new(s: &'a str, style: Option<Style>) -> StyledStr<'a>
pub fn new(s: &'a str, style: Option<Style>) -> StyledStr<'a>
Creates a new styled string from the given string and an optional style.
Sourcepub fn styled(s: &'a str, style: Style) -> StyledStr<'a>
pub fn styled(s: &'a str, style: Style) -> StyledStr<'a>
Creates a new styled string from the given string and style.
Sourcepub fn plain(s: &'a str) -> StyledStr<'a>
pub fn plain(s: &'a str) -> StyledStr<'a>
Creates a new styled string from the given string without a style.
Sourcepub fn strikethrough(self) -> Self
pub fn strikethrough(self) -> Self
Sets the strikethrough effect for this styled string.
Trait Implementations§
Source§impl<'a, 'b> From<&'b StyledStr<'a>> for ANSIString<'a>
impl<'a, 'b> From<&'b StyledStr<'a>> for ANSIString<'a>
Source§fn from(s: &'b StyledStr<'a>) -> ANSIString<'a>
fn from(s: &'b StyledStr<'a>) -> ANSIString<'a>
Converts to this type from the input type.
Source§impl<'a, 'b> From<&'b StyledStr<'a>> for StyledString
impl<'a, 'b> From<&'b StyledStr<'a>> for StyledString
Source§fn from(s: &'b StyledStr<'a>) -> StyledString
fn from(s: &'b StyledStr<'a>) -> StyledString
Converts to this type from the input type.
Source§impl<'a, 's> From<&'a StyledStr<'s>> for StyledString
impl<'a, 's> From<&'a StyledStr<'s>> for StyledString
Source§fn from(s: &'a StyledStr<'s>) -> StyledString
fn from(s: &'a StyledStr<'s>) -> StyledString
Converts to this type from the input type.
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<'a> From<StyledStr<'a>> for ANSIString<'a>
impl<'a> From<StyledStr<'a>> for ANSIString<'a>
Source§fn from(s: StyledStr<'a>) -> ANSIString<'a>
fn from(s: StyledStr<'a>) -> ANSIString<'a>
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<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<'s> From<StyledStr<'s>> for StyledString
impl<'s> From<StyledStr<'s>> for StyledString
Source§fn from(s: StyledStr<'s>) -> StyledString
fn from(s: StyledStr<'s>) -> StyledString
Converts to this type from the input type.
impl<'a> StructuralPartialEq for StyledStr<'a>
Auto Trait Implementations§
impl<'a> Freeze for StyledStr<'a>
impl<'a> RefUnwindSafe for StyledStr<'a>
impl<'a> Send for StyledStr<'a>
impl<'a> Sync for StyledStr<'a>
impl<'a> Unpin for StyledStr<'a>
impl<'a> UnwindSafe for StyledStr<'a>
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