pub struct Span<'a> {
pub content: Cow<'a, str>,
pub style: Style,
}
Expand description
A string where all graphemes have the same style.
Fields§
§content: Cow<'a, str>
§style: Style
Implementations§
Source§impl<'a> Span<'a>
impl<'a> Span<'a>
Sourcepub fn styled<T>(content: T, style: Style) -> Span<'a>
pub fn styled<T>(content: T, style: Style) -> Span<'a>
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> StructuralPartialEq for Span<'a>
Auto Trait Implementations§
impl<'a> Freeze for Span<'a>
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§
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