pub struct Line<'a> {
pub spans: Vec<Span<'a>>,
pub alignment: Option<Alignment>,
}
Fields§
§spans: Vec<Span<'a>>
§alignment: Option<Alignment>
Implementations§
source§impl<'a> Line<'a>
impl<'a> Line<'a>
sourcepub fn width(&self) -> usize
pub fn width(&self) -> usize
Returns the width of the underlying string.
Examples
let line = Line::from(vec![
Span::styled("My", Style::default().fg(Color::Yellow)),
Span::raw(" text"),
]);
assert_eq!(7, line.width());
sourcepub fn patch_style(&mut self, style: Style)
pub fn patch_style(&mut self, style: Style)
Patches the style of each Span in an existing Line, adding modifiers from the given style.
Examples
let style = Style::default().fg(Color::Yellow).add_modifier(Modifier::ITALIC);
let mut raw_line = Line::from(vec![
Span::raw("My"),
Span::raw(" text"),
]);
let mut styled_line = Line::from(vec![
Span::styled("My", style),
Span::styled(" text", style),
]);
assert_ne!(raw_line, styled_line);
raw_line.patch_style(style);
assert_eq!(raw_line, styled_line);
sourcepub fn reset_style(&mut self)
pub fn reset_style(&mut self)
Resets the style of each Span in the Line.
Equivalent to calling patch_style(Style::reset())
.
Examples
let mut line = Line::from(vec![
Span::styled("My", Style::default().fg(Color::Yellow)),
Span::styled(" text", Style::default().add_modifier(Modifier::BOLD)),
]);
line.reset_style();
assert_eq!(Style::reset(), line.spans[0].style);
assert_eq!(Style::reset(), line.spans[1].style);
Trait Implementations§
source§impl<'a> PartialEq<Line<'a>> for Line<'a>
impl<'a> PartialEq<Line<'a>> for Line<'a>
impl<'a> Eq for Line<'a>
impl<'a> StructuralEq for Line<'a>
impl<'a> StructuralPartialEq for Line<'a>
Auto Trait Implementations§
impl<'a> RefUnwindSafe for Line<'a>
impl<'a> Send for Line<'a>
impl<'a> Sync for Line<'a>
impl<'a> Unpin for Line<'a>
impl<'a> UnwindSafe for Line<'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