Expand description
A string where all graphemes have the same style.
Fields
content: Cow<'a, str>
style: Style
Implementations
sourceimpl<'a> Span<'a>
impl<'a> Span<'a>
sourcepub fn styled<T>(content: T, style: Style) -> Span<'a> where
T: Into<Cow<'a, str>>,
pub fn styled<T>(content: T, style: Style) -> Span<'a> where
T: Into<Cow<'a, str>>,
Create a span with a style.
Examples
let style = Style::default().fg(Color::Yellow).add_modifier(Modifier::ITALIC);
Span::styled("My text", style);
Span::styled(String::from("My text"), style);
sourcepub fn styled_graphemes(
&'a self,
base_style: Style
) -> impl Iterator<Item = StyledGrapheme<'a>>
pub fn styled_graphemes(
&'a self,
base_style: Style
) -> impl Iterator<Item = StyledGrapheme<'a>>
Returns an iterator over the graphemes held by this span.
base_style
is the Style
that will be patched with each grapheme Style
to get
the resulting Style
.
Examples
let style = Style::default().fg(Color::Yellow);
let span = Span::styled("Text", style);
let style = Style::default().fg(Color::Green).bg(Color::Black);
let styled_graphemes = span.styled_graphemes(style);
assert_eq!(
vec![
StyledGrapheme {
symbol: "T",
style: Style {
fg: Some(Color::Yellow),
bg: Some(Color::Black),
add_modifier: Modifier::empty(),
sub_modifier: Modifier::empty(),
},
},
StyledGrapheme {
symbol: "e",
style: Style {
fg: Some(Color::Yellow),
bg: Some(Color::Black),
add_modifier: Modifier::empty(),
sub_modifier: Modifier::empty(),
},
},
StyledGrapheme {
symbol: "x",
style: Style {
fg: Some(Color::Yellow),
bg: Some(Color::Black),
add_modifier: Modifier::empty(),
sub_modifier: Modifier::empty(),
},
},
StyledGrapheme {
symbol: "t",
style: Style {
fg: Some(Color::Yellow),
bg: Some(Color::Black),
add_modifier: Modifier::empty(),
sub_modifier: Modifier::empty(),
},
},
],
styled_graphemes.collect::<Vec<StyledGrapheme>>()
);
Trait Implementations
impl<'a> Eq for Span<'a>
impl<'a> StructuralEq for Span<'a>
impl<'a> StructuralPartialEq for Span<'a>
Auto Trait Implementations
impl<'a> RefUnwindSafe for Span<'a>
impl<'a> Send for Span<'a>
impl<'a> Sync for Span<'a>
impl<'a> Unpin for Span<'a>
impl<'a> UnwindSafe for Span<'a>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more