pub struct StringPool { /* private fields */ }Expand description
Every string too long to sit inside a Data, with the character count of
each one remembered.
A position on a string counts characters, so an index or a slice has to find
where character i starts. Counting a long string’s characters for every
one of those would turn a loop over it into quadratic work, so a slot’s
count is taken once and kept until the slot holds a different string. A
string whose character count equals its byte length holds nothing but
single-byte characters, and on it a character position is a byte position;
that is the route indexing and slicing take. The cursor remembers where the
last walk stopped, so stepping through a multi-byte string forwards resumes
there instead of restarting at its first byte.
The pool also carries the collector’s marks for its strings. Interning a
string hands out a slot it found by its text, and the slot it finds has to
count as reached by a cycle in progress, which is what Self::shade does
without the interning caller needing the collector.
Implementations§
Source§impl StringPool
impl StringPool
pub fn with_capacity(capacity: usize) -> Self
pub fn from_strings(strings: Vec<String>) -> Self
pub const fn len(&self) -> usize
pub const fn is_empty(&self) -> bool
pub fn push(&mut self, value: String)
pub fn iter(&self) -> impl Iterator<Item = &String>
Sourcepub fn get_mut(&mut self, index: usize) -> &mut String
pub fn get_mut(&mut self, index: usize) -> &mut String
A slot to write a different string into. What was worked out about the slot describes the string being replaced, so it goes.
Sourcepub fn release(&mut self, index: usize)
pub fn release(&mut self, index: usize)
Empties a slot the collector freed. A long string’s buffer goes back to the allocator rather than waiting in a dead slot for the next string written there.
Sourcepub fn char_len(&self, id: usize) -> usize
pub fn char_len(&self, id: usize) -> usize
The character count of the string in id, walked once and then
remembered on the slot.
Sourcepub fn is_ascii(&self, id: usize) -> bool
pub fn is_ascii(&self, id: usize) -> bool
Whether every character in id takes a single byte, answered from the
remembered count rather than a second walk.
Sourcepub fn byte_offset(&self, id: usize, char_idx: usize) -> usize
pub fn byte_offset(&self, id: usize, char_idx: usize) -> usize
The byte offset character char_idx starts at. The string has at least
char_idx characters; at exactly that many the answer is its byte
length, which is what a slice bound on the end of the string asks for.
Trait Implementations§
Source§impl Default for StringPool
impl Default for StringPool
Auto Trait Implementations§
impl !Freeze for StringPool
impl !RefUnwindSafe for StringPool
impl !Sync for StringPool
impl Send for StringPool
impl Unpin for StringPool
impl UnsafeUnpin for StringPool
impl UnwindSafe for StringPool
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
§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling [Attribute] value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi [Quirk] value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the [Condition] value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);