pub struct Document { /* private fields */ }std only.Expand description
A YAML document with byte-faithful source preservation, typed data access, and path-targeted edits.
Document carries three coordinated views of the same input:
an immutable green tree that reproduces the source byte-for-byte,
a typed Value for data access, and an internal span tree
that maps any Value-shaped path back to a byte range. Edits
flow through Document::replace_span (the primitive) and
Document::set (the path-shaped wrapper); untouched bytes —
indentation, comments, blank lines, sibling entries — are
preserved verbatim.
§Examples
Read-only round-trip:
use noyalib::cst::parse_document;
let src = "name: noyalib # the project\nversion: 0.0.1\n";
let doc = parse_document(src).unwrap();
assert_eq!(doc.to_string(), src);Path-targeted edit:
use noyalib::cst::parse_document;
let mut doc = parse_document("name: foo\nversion: 0.0.1\n").unwrap();
doc.set("version", "0.0.2").unwrap();
assert_eq!(doc.to_string(), "name: foo\nversion: 0.0.2\n");Implementations§
Source§impl Document
impl Document
Sourcepub fn anchors(&self) -> Vec<AnchorInfo>
pub fn anchors(&self) -> Vec<AnchorInfo>
Every &name declaration in this document, in source order.
§Examples
use noyalib::cst::parse_document;
let doc = parse_document(
"defaults: &cfg\n port: 8080\nserver:\n <<: *cfg\n",
).unwrap();
let anchors = doc.anchors();
assert_eq!(anchors.len(), 1);
assert_eq!(anchors[0].name, "cfg");Sourcepub fn aliases(&self) -> Vec<AliasInfo>
pub fn aliases(&self) -> Vec<AliasInfo>
Every *name reference in this document, in source order.
§Examples
use noyalib::cst::parse_document;
let doc = parse_document("a: &x 1\nb: *x\nc: *x\n").unwrap();
let aliases = doc.aliases();
assert_eq!(aliases.len(), 2);Sourcepub fn aliases_of(&self, name: &str) -> Vec<AliasInfo>
pub fn aliases_of(&self, name: &str) -> Vec<AliasInfo>
Aliases whose name matches name, in source order.
§Examples
use noyalib::cst::parse_document;
let doc = parse_document("a: &x 1\nb: &y 2\nc: *x\nd: *y\n").unwrap();
let xs = doc.aliases_of("x");
assert_eq!(xs.len(), 1);
assert_eq!(xs[0].name, "x");Sourcepub fn materialise_alias_at(&mut self, position: usize) -> Result<()>
pub fn materialise_alias_at(&mut self, position: usize) -> Result<()>
Replace the *name alias whose mark begins at byte
position with the source text of the matching &name’s
scalar value.
After the splice, the alias’s site holds an independent copy of the anchored scalar — subsequent edits to the anchored value do not propagate to it.
§Errors
positiondoes not start an*nametoken.- The named anchor is not declared earlier in source order.
- The anchored value is not a scalar (multi-line block
collections require manual handling — read the anchor’s
span via
Self::anchorsand splice withSelf::replace_span). - The same parse-after-edit errors as
Self::replace_span.
§Examples
use noyalib::cst::parse_document;
let mut doc = parse_document("a: &x 7\nb: *x\n").unwrap();
let alias = doc.aliases()[0].clone();
doc.materialise_alias_at(alias.mark_span.0).unwrap();
assert!(!doc.to_string().contains("*x"));
assert!(doc.to_string().contains("b: 7"));Sourcepub fn materialise_aliases_of(&mut self, name: &str) -> Result<usize>
pub fn materialise_aliases_of(&mut self, name: &str) -> Result<usize>
Materialise every alias whose name matches name. Returns
the count of aliases replaced.
Aliases are processed in reverse source order so each splice’s offsets stay valid for later (earlier in source) aliases.
§Errors
As Self::materialise_alias_at. The first failing alias
aborts the batch — already-materialised aliases stay
materialised, the rest are unchanged.
§Examples
use noyalib::cst::parse_document;
let mut doc = parse_document("a: &x 7\nb: *x\nc: *x\n").unwrap();
let n = doc.materialise_aliases_of("x").unwrap();
assert_eq!(n, 2);
assert!(!doc.to_string().contains('*'));Sourcepub fn rename_anchor(&mut self, old: &str, new: &str) -> Result<usize>
pub fn rename_anchor(&mut self, old: &str, new: &str) -> Result<usize>
Rename every &old anchor declaration and every *old
alias reference to new in one atomic pass. Returns the
total number of touched sites (anchors + aliases).
Splices run in reverse source order so each successive splice’s offsets stay valid for earlier sites. The whole rename is byte-faithful outside the touched marks — comments, blank lines, and sibling formatting survive verbatim.
§Errors
newis empty or contains characters that would not be accepted as a YAML anchor name (any of the flow indicators,[]{}or whitespace per YAML 1.2 §6.9.2).olddoes not match any anchor or alias in the document (so the call is a no-op the user probably did not intend) — surfaced as an error rather than a silent zero-count.- The same parse-after-edit errors as
crate::cst::Document::replace_spanfor any individual splice. The first failing splice aborts the batch; already-renamed sites stay renamed, so callers should treat a partial-failure error as a recoverable state and inspect the document.
§Examples
use noyalib::cst::parse_document;
let mut doc = parse_document(
"defaults: &cfg\n port: 8080\nservice:\n <<: *cfg\nbackup: *cfg\n",
).unwrap();
// Rename `cfg` → `defaults`. The single `&cfg` declaration
// and both `*cfg` references are updated in one call.
let n = doc.rename_anchor("cfg", "defaults").unwrap();
assert_eq!(n, 3); // 1 anchor + 2 aliases
let out = doc.to_string();
assert!(!out.contains("&cfg"));
assert!(!out.contains("*cfg"));
assert!(out.contains("&defaults"));
assert!(out.contains("*defaults"));Source§impl Document
impl Document
Sourcepub fn comments_at(&self, path: &str) -> CommentBundle
pub fn comments_at(&self, path: &str) -> CommentBundle
Comments decorating the node at path, classified by position.
Returns an empty CommentBundle when path does not
resolve. Path syntax matches Document::span_at —
foo.bar, items[0], items[0].name. Wildcard /
recursive-descent segments are not supported (a non-singular
span has no canonical “above” line).
§Examples
use noyalib::cst::parse_document;
let src = "# A multi-line\n# leading block\nport: 8080 # inline\n";
let doc = parse_document(src).unwrap();
let b = doc.comments_at("port");
assert_eq!(b.before.len(), 2);
assert_eq!(b.inline.as_ref().unwrap().text, " inline");Source§impl Document
impl Document
Sourcepub fn as_value(&self) -> Ref<'_, Value>
pub fn as_value(&self) -> Ref<'_, Value>
Borrow the typed Value view of the document.
On the first call after an edit (or a fresh parse), this
triggers a one-shot parse of the current source into the
internal Value / SpanTree cache. Subsequent calls on the
same document are O(1) until the next edit invalidates the
cache. Code that batches many edits without reading the
typed view in between never pays the typed-tree cost.
§Examples
use noyalib::cst::parse_document;
let doc = parse_document("name: noyalib\n").unwrap();
assert_eq!(doc.as_value()["name"].as_str(), Some("noyalib"));Sourcepub fn source(&self) -> &str
pub fn source(&self) -> &str
The original source bytes for this document. After an edit reflects the current source.
§Examples
use noyalib::cst::parse_document;
let src = "key: 1\n";
let doc = parse_document(src).unwrap();
assert_eq!(doc.source(), src);Sourcepub fn span_at(&self, path: &str) -> Option<(usize, usize)>
pub fn span_at(&self, path: &str) -> Option<(usize, usize)>
Resolve a path to the byte range of the value at that path,
if any.
Path syntax matches the rest of the crate (foo.bar,
items[0], items[0].name). Wildcard / recursive-descent
segments are not supported here — they have no single span.
§Examples
use noyalib::cst::parse_document;
let doc = parse_document("name: noyalib\nversion: 0.0.1\n").unwrap();
let (s, e) = doc.span_at("version").unwrap();
assert_eq!(&doc.source()[s..e], "0.0.1");Sourcepub fn validate(&self) -> Result<()>
pub fn validate(&self) -> Result<()>
Verify that the current source re-parses cleanly.
Document::set (and the rest of the path-shaped edit API)
uses a localised-repair fast path that gates each splice on
the fragment’s own scanner-level validation but commits
optimistically: a structurally invalid splice across the
whole document — for example, a value like [ that opens a
flow collection never closed at end-of-input — passes the
fragment check and only surfaces when the typed view is
next read. as_value, span_at, get, and any path-shaped
API panic on first access in that state.
validate is the non-panicking eager check: call it after
an edit (or before handing the document to a downstream
consumer) to surface any document-level parse error as a
regular Result. On success, the typed cache is populated
as a side-effect so a subsequent as_value call is free.
§Errors
Returns the underlying parse error if the source no longer parses as a single YAML document.
§Examples
Eagerly validate after an edit that may not be safe:
use noyalib::cst::parse_document;
let mut doc = parse_document("name: foo\n").unwrap();
// `[` opens a flow seq that is never closed — the local
// repair commits optimistically, but the document is now
// structurally broken. `validate` surfaces that as an
// error rather than waiting for the next typed-view read.
doc.set("name", "[").unwrap();
assert!(doc.validate().is_err());Validate a freshly-parsed document — always succeeds:
use noyalib::cst::parse_document;
let doc = parse_document("name: foo\n").unwrap();
assert!(doc.validate().is_ok());Sourcepub fn get(&self, path: &str) -> Option<&str>
pub fn get(&self, path: &str) -> Option<&str>
Return the source slice of the value at path.
§Examples
use noyalib::cst::parse_document;
let doc = parse_document("items:\n - one\n - two\n").unwrap();
assert_eq!(doc.get("items[1]"), Some("two"));Sourcepub fn replace_span(
&mut self,
start: usize,
end: usize,
replacement: &str,
) -> Result<()>
pub fn replace_span( &mut self, start: usize, end: usize, replacement: &str, ) -> Result<()>
Replace the bytes in start..end with replacement and
re-parse. The caller is responsible for replacement being a
syntactically valid fragment in that position; if the spliced
source fails to parse, the original document is left
unchanged and the parse error is returned.
§Errors
Error::Parseif the resulting source is not valid YAML.Error::Parseifstart..endis out of bounds or not a character boundary.
§Examples
use noyalib::cst::parse_document;
let mut doc = parse_document("a: 1\n").unwrap();
let (s, e) = doc.span_at("a").unwrap();
doc.replace_span(s, e, "42").unwrap();
assert_eq!(doc.to_string(), "a: 42\n");Sourcepub fn last_repair_scope(&self) -> Option<RepairScope>
pub fn last_repair_scope(&self) -> Option<RepairScope>
Last successful repair scope, if any. Useful for tests and
instrumentation; returns None for a freshly-parsed
document or when the most recent edit fell back to a full
re-parse.
Sourcepub fn set(&mut self, path: &str, fragment: &str) -> Result<()>
pub fn set(&mut self, path: &str, fragment: &str) -> Result<()>
Replace the value at path with fragment.
fragment is spliced verbatim into the source — the caller
supplies the YAML representation. This deliberately matches
no scalar style automatically; choose double-quoted, plain,
or block style to suit. Auto-formatting (the Emit trait
from the design doc) is a follow-up.
§Errors
Error::Parse(...)with “path not found” ifpathdoes not resolve in the current document.- The same errors as
Document::replace_spanotherwise.
§Examples
use noyalib::cst::parse_document;
let mut doc = parse_document("name: foo\nversion: 0.0.1\n").unwrap();
doc.set("version", "0.0.2").unwrap();
assert_eq!(doc.to_string(), "name: foo\nversion: 0.0.2\n");Sourcepub fn set_value(&mut self, path: &str, value: &Value) -> Result<()>
pub fn set_value(&mut self, path: &str, value: &Value) -> Result<()>
Replace the value at path with a typed Value, formatting
the YAML fragment to match the existing scalar style at the
target site.
Style matching:
PlainScalar— emit plain when safe, double-quoted otherwise.SingleQuotedScalar— wrap in'…'(only string values).DoubleQuotedScalar— wrap in"…"with standard escapes (only string values).LiteralScalar/FoldedScalar— currently rejected; block scalar formatting is a follow-up.
Non-string values (numbers, booleans, null) are emitted plain regardless of the existing style — quoting them would change the parsed type round-trip.
§Errors
- Path not found.
- Target is a collection or block scalar.
- Caller passed a
Sequence/Mapping(usesetwith a pre-formatted fragment for those —set_valueis scalar-only for now). - The same errors as
Document::replace_spanotherwise.
§Examples
use noyalib::cst::parse_document;
use noyalib::Value;
let mut doc = parse_document("name: noyalib\nversion: 0.0.1\n").unwrap();
doc.set_value("version", &Value::String("0.0.2".into())).unwrap();
assert_eq!(doc.to_string(), "name: noyalib\nversion: 0.0.2\n");Sourcepub fn remove(&mut self, path: &str) -> Result<()>
pub fn remove(&mut self, path: &str) -> Result<()>
Remove the value at path along with its surrounding entry
(key + colon for mappings, - indicator for sequences).
Trailing whitespace and the line break are removed too so the
surrounding entries close up with no orphan blank line.
Restrictions in this phase:
- Block context only — flow-collection entry removal (
[a, b, c]→[a, c]) is a follow-up. - The value must end on the line where its key /
-indicator appears (single-line scalars). Multi-line values and nested collections are deferred to the same follow-up that handles block-scalar replacement inset_value. - Removing the only entry of a block mapping or sequence is
rejected — the result would parse differently (an empty
block becomes
null), and the caller needs to express that intent explicitly.
§Errors
- Path not found.
- Restrictions above.
- The same parse-after-edit errors as
Document::replace_span; on failure the document is left unchanged.
§Examples
use noyalib::cst::parse_document;
let mut doc = parse_document("a: 1\nb: 2\nc: 3\n").unwrap();
doc.remove("b").unwrap();
assert_eq!(doc.to_string(), "a: 1\nc: 3\n");Sourcepub fn push_back(&mut self, path: &str, fragment: &str) -> Result<()>
pub fn push_back(&mut self, path: &str, fragment: &str) -> Result<()>
Append a new item to the block sequence at path.
fragment is the YAML representation of the value — the
- indicator and the surrounding indentation are synthesized
from the existing items so the new line matches the file’s
shape. Block sequences only in this phase; flow sequences
([…]) and empty sequences are rejected.
§Errors
pathdoes not resolve to a sequence.- The sequence is a flow collection (
[…]). - The sequence has no existing items to anchor indentation on.
- The same parse-after-edit errors as
Document::replace_span.
§Examples
use noyalib::cst::parse_document;
let mut doc = parse_document("items:\n - one\n - two\n").unwrap();
doc.push_back("items", "three").unwrap();
assert_eq!(doc.to_string(), "items:\n - one\n - two\n - three\n");Sourcepub fn indent_unit(&self) -> usize
pub fn indent_unit(&self) -> usize
Detect the indentation unit (in spaces) used by this document.
Walks the source line-by-line, looks for any pair of
consecutive non-empty/non-comment lines where the second is
more deeply indented than the first, and returns the smallest
such delta — that is the file’s “indent step”, typically 2 or
4 spaces. A document with no nested structure (or only
top-level keys) has no detectable step; the default 2 is
returned in that case.
Used internally by the crate::cst::Entry insertion paths
to keep the inserted YAML’s inner indentation consistent with
what the rest of the file already uses (2-space file → 2-space
inserts; 4-space file → 4-space inserts). Exposed publicly so
callers building their own emission paths can match the same
convention.
§Examples
use noyalib::cst::parse_document;
let two_space = parse_document(
"metadata:\n labels:\n app: noyalib\n",
).unwrap();
assert_eq!(two_space.indent_unit(), 2);
let four_space = parse_document(
"metadata:\n labels:\n app: noyalib\n",
).unwrap();
assert_eq!(four_space.indent_unit(), 4);
// No nested structure — defaults to 2.
let flat = parse_document("a: 1\nb: 2\n").unwrap();
assert_eq!(flat.indent_unit(), 2);Sourcepub fn dominant_quote_style(&self) -> ScalarStyle
pub fn dominant_quote_style(&self) -> ScalarStyle
Inspect the document and return the dominant scalar quote
style — Plain, SingleQuoted, or DoubleQuoted. Used by
the crate::cst::Entry insert helpers to make new
scalars adopt the file’s existing convention rather than
the serializer’s hard-coded default.
The detection scans every plain / single-quoted /
double-quoted scalar leaf in the green tree, picks the
majority, and breaks ties in favour of the simpler form
(Plain > SingleQuoted > DoubleQuoted). Empty
documents and documents with no string-shaped scalars
default to Plain.
§Examples
use noyalib::cst::parse_document;
use noyalib::ScalarStyle;
let single = parse_document("a: 'one'\nb: 'two'\n").unwrap();
assert_eq!(single.dominant_quote_style(), ScalarStyle::SingleQuoted);
let double = parse_document("a: \"one\"\nb: \"two\"\n").unwrap();
assert_eq!(double.dominant_quote_style(), ScalarStyle::DoubleQuoted);
let plain = parse_document("a: one\nb: two\n").unwrap();
assert_eq!(plain.dominant_quote_style(), ScalarStyle::Plain);Sourcepub fn dominant_flow_style(&self) -> FlowStyle
pub fn dominant_flow_style(&self) -> FlowStyle
Inspect the document and return the dominant collection
style — FlowStyle::Block or FlowStyle::Auto
(equivalent to “flow”). Used by Entry::insert_value to
decide whether a typed mapping / sequence emission should
use block or flow form.
The detection counts top-level BlockMapping /
BlockSequence vs FlowMapping / FlowSequence leaves
and picks the majority. Empty / scalar-only documents
default to Block.
§Examples
use noyalib::cst::parse_document;
use noyalib::FlowStyle;
let block = parse_document("a:\n - 1\n - 2\n").unwrap();
assert_eq!(block.dominant_flow_style(), FlowStyle::Block);
let flow = parse_document("a: [1, 2, 3]\nb: [4, 5]\n").unwrap();
assert_eq!(flow.dominant_flow_style(), FlowStyle::Auto);Sourcepub fn insert_entry(
&mut self,
mapping_path: &str,
key: &str,
fragment: &str,
) -> Result<()>
pub fn insert_entry( &mut self, mapping_path: &str, key: &str, fragment: &str, ) -> Result<()>
Insert a new key: fragment entry into the block mapping at
mapping_path. The mapping-side analogue of
Document::push_back.
Behaves like set when the key already exists (the value is
replaced losslessly). When the key is new, a sibling line is
spliced after the last existing entry, with the indent matched
to the last entry’s key column so the file stays canonical.
Block mappings only in this phase; flow mappings ({…}) and
empty mappings are rejected.
§Errors
mapping_pathdoes not resolve to a mapping.- The mapping is empty (no anchor for indentation; use
setwith a fragment instead). - The same parse-after-edit errors as
Document::replace_span.
§Examples
use noyalib::cst::parse_document;
let mut doc = parse_document(
"metadata:\n labels:\n app: noyalib\n",
).unwrap();
doc.insert_entry("metadata.labels", "env", "prod").unwrap();
let out = doc.to_string();
assert!(out.contains("app: noyalib"));
assert!(out.contains("env: prod"));Sourcepub fn insert_after(&mut self, item_path: &str, fragment: &str) -> Result<()>
pub fn insert_after(&mut self, item_path: &str, fragment: &str) -> Result<()>
Insert a new sequence item immediately after the item at
item_path (e.g. "items[1]").
fragment is the YAML representation of the value; the
- indicator and indentation are derived from the item at
item_path.
§Errors
item_pathdoes not end in an index.- The path does not resolve to a sequence item in a block sequence.
- The same parse-after-edit errors as
Document::replace_span.
§Examples
use noyalib::cst::parse_document;
let mut doc = parse_document("items:\n - one\n - three\n").unwrap();
doc.insert_after("items[0]", "two").unwrap();
assert_eq!(
doc.to_string(),
"items:\n - one\n - two\n - three\n",
);Source§impl Document
impl Document
Sourcepub fn entry<'a>(&'a mut self, path: &str) -> Entry<'a>
pub fn entry<'a>(&'a mut self, path: &str) -> Entry<'a>
Return a path-shaped mutable handle to the node at path.
The handle is the “pro” mutation interface — chainable,
composable, ergonomic for nested edits — that complements the
functional Document::set / Document::remove /
Document::push_back / Document::insert_after methods
(all of which remain available for direct one-shot operations).
entry itself is infallible — the path is recorded but not
resolved at this point. Operations on the returned entry
surface path-resolution and splice-failure errors via their
own Result.
§Examples
use noyalib::cst::parse_document;
let mut doc = parse_document(
"metadata:\n labels:\n app: noyalib\n",
).unwrap();
doc.entry("metadata.labels").insert("env", "prod").unwrap();
let out = doc.to_string();
assert!(out.contains("app: noyalib"));
assert!(out.contains("env: prod"));Trait Implementations§
Auto Trait Implementations§
impl !Freeze for Document
impl !RefUnwindSafe for Document
impl !Sync for Document
impl Send for Document
impl Unpin for Document
impl UnsafeUnpin for Document
impl UnwindSafe for Document
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreimpl<T> MaybeSendSync for T
Source§impl<D> OwoColorize for D
impl<D> OwoColorize for D
Source§fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
Source§fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
Source§fn black(&self) -> FgColorDisplay<'_, Black, Self>
fn black(&self) -> FgColorDisplay<'_, Black, Self>
Source§fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
Source§fn red(&self) -> FgColorDisplay<'_, Red, Self>
fn red(&self) -> FgColorDisplay<'_, Red, Self>
Source§fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
Source§fn green(&self) -> FgColorDisplay<'_, Green, Self>
fn green(&self) -> FgColorDisplay<'_, Green, Self>
Source§fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
Source§fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
Source§fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
Source§fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
Source§fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
Source§fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
Source§fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
Source§fn white(&self) -> FgColorDisplay<'_, White, Self>
fn white(&self) -> FgColorDisplay<'_, White, Self>
Source§fn on_white(&self) -> BgColorDisplay<'_, White, Self>
fn on_white(&self) -> BgColorDisplay<'_, White, Self>
Source§fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
Source§fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
Source§fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
Source§fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
Source§fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
Source§fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
Source§fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
Source§fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
Source§fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
Source§fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
Source§fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
Source§fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
Source§fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
Source§fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
Source§fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
Source§fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
Source§fn bold(&self) -> BoldDisplay<'_, Self>
fn bold(&self) -> BoldDisplay<'_, Self>
Source§fn dimmed(&self) -> DimDisplay<'_, Self>
fn dimmed(&self) -> DimDisplay<'_, Self>
Source§fn italic(&self) -> ItalicDisplay<'_, Self>
fn italic(&self) -> ItalicDisplay<'_, Self>
Source§fn underline(&self) -> UnderlineDisplay<'_, Self>
fn underline(&self) -> UnderlineDisplay<'_, Self>
Source§fn blink(&self) -> BlinkDisplay<'_, Self>
fn blink(&self) -> BlinkDisplay<'_, Self>
Source§fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
Source§fn reversed(&self) -> ReversedDisplay<'_, Self>
fn reversed(&self) -> ReversedDisplay<'_, Self>
Source§fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
Source§fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::fg or
a color-specific method, such as OwoColorize::green, Read moreSource§fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::bg or
a color-specific method, such as OwoColorize::on_yellow, Read moreSource§fn fg_rgb<const R: u8, const G: u8, const B: u8>(
&self,
) -> FgColorDisplay<'_, CustomColor<R, G, B>, Self>
fn fg_rgb<const R: u8, const G: u8, const B: u8>( &self, ) -> FgColorDisplay<'_, CustomColor<R, G, B>, Self>
Source§fn bg_rgb<const R: u8, const G: u8, const B: u8>(
&self,
) -> BgColorDisplay<'_, CustomColor<R, G, B>, Self>
fn bg_rgb<const R: u8, const G: u8, const B: u8>( &self, ) -> BgColorDisplay<'_, CustomColor<R, G, B>, Self>
Source§fn truecolor(&self, r: u8, g: u8, b: u8) -> FgDynColorDisplay<'_, Rgb, Self>
fn truecolor(&self, r: u8, g: u8, b: u8) -> FgDynColorDisplay<'_, Rgb, Self>
Source§fn on_truecolor(&self, r: u8, g: u8, b: u8) -> BgDynColorDisplay<'_, Rgb, Self>
fn on_truecolor(&self, r: u8, g: u8, b: u8) -> BgDynColorDisplay<'_, Rgb, Self>
Source§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
Source§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();Source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
Source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
Source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
Source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Source§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();Source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
Source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
Source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
Source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Source§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();Source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Source§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();Source§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.
Source§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);Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> ToCompactString for Twhere
T: Display,
impl<T> ToCompactString for Twhere
T: Display,
Source§fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
ToCompactString::to_compact_string() Read moreSource§fn to_compact_string(&self) -> CompactString
fn to_compact_string(&self) -> CompactString
CompactString. Read more