pub struct StyledText { /* private fields */ }Expand description
One text flow carrying any number of styles.
The source is stored once. Its private ranges are canonical: they are non-empty, cover the source in order, end only at whole-string grapheme boundaries, and never place equal styles beside each other. Newline and horizontal tab are admitted source controls; layout replaces tabs under this value’s policy, while direct text rendering preserves them.
Implementations§
Source§impl StyledText
impl StyledText
Sourcepub fn new(text: impl Into<String>, style: TextStyle) -> Self
pub fn new(text: impl Into<String>, style: TextStyle) -> Self
Creates one uniformly styled text flow.
§Panics
Panics when text contains a control character other than newline or
horizontal tab. Rendered ANSI belongs to the output domain, not this
source-text domain.
Sourcepub fn try_from_spans<I, S>(spans: I) -> Result<Self, StyledTextError>
pub fn try_from_spans<I, S>(spans: I) -> Result<Self, StyledTextError>
Joins input segments into one validated, canonical text flow.
§Panics
Panics when any segment contains a control character other than newline or horizontal tab.
Sourcepub fn spans(&self) -> impl Iterator<Item = (&str, &TextStyle)>
pub fn spans(&self) -> impl Iterator<Item = (&str, &TextStyle)>
Returns the canonical styled segments in source order.
Sourcepub fn tab_policy(self, tab_policy: TabPolicy) -> Self
pub fn tab_policy(self, tab_policy: TabPolicy) -> Self
Sets the policy used when this text participates in layout.
Direct text rendering preserves the source tab characters and ignores this layout-only property.
Sourcepub fn reset_tab_policy(self) -> Self
pub fn reset_tab_policy(self) -> Self
Restores the default layout policy of four spaces per tab.
Sourcepub const fn get_tab_policy(&self) -> Option<&TabPolicy>
pub const fn get_tab_policy(&self) -> Option<&TabPolicy>
Returns the explicitly configured layout policy, if any.
Trait Implementations§
Source§impl Clone for StyledText
impl Clone for StyledText
Source§fn clone(&self) -> StyledText
fn clone(&self) -> StyledText
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for StyledText
impl Debug for StyledText
Source§impl Default for StyledText
impl Default for StyledText
Source§fn default() -> StyledText
fn default() -> StyledText
Source§impl From<&str> for StyledText
impl From<&str> for StyledText
Source§impl From<String> for StyledText
impl From<String> for StyledText
Source§impl From<StyledText> for BlockTitle
impl From<StyledText> for BlockTitle
Source§fn from(text: StyledText) -> Self
fn from(text: StyledText) -> Self
Source§impl PartialEq for StyledText
impl PartialEq for StyledText
Source§fn eq(&self, other: &StyledText) -> bool
fn eq(&self, other: &StyledText) -> bool
self and other values to be equal, and is used by ==.