Skip to main content

Error

Enum Error 

Source
#[non_exhaustive]
pub enum Error {
Show 28 variants Parse(String), ParseWithLocation { message: String, location: Location, }, Serialize(String), Deserialize(String), DeserializeWithLocation { message: String, location: Location, }, Io(Error), Custom(String), RecursionLimitExceeded { depth: usize, }, DuplicateKey(String), KeyCollision(String), RepetitionLimitExceeded, Budget(BudgetBreach), UnknownAnchor(String), UnknownAnchorAt { name: String, location: Location, suggestion: Option<(String, Location)>, }, MissingField(String), UnknownField(String), ScalarInMergeElement, SequenceInMergeElement, TaggedInMerge, Invalid(String), TypeMismatch { expected: &'static str, found: String, }, Shared(Arc<Error>), EndOfStream, MoreThanOneDocument, ScalarInMerge, EmptyTag, FailedToParseNumber(String), Message(String, Option<usize>),
}
Expand description

§Examples

use noyalib::{from_str, Error, Value};
let err = from_str::<Value>("a: [unclosed").unwrap_err();
assert!(matches!(err, Error::Parse(_) | Error::ParseWithLocation { .. }));

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Parse(String)

Error during YAML parsing.

§Examples

let _e = noyalib::Error::Parse("unexpected token".into());
§

ParseWithLocation

Error during YAML parsing with location information.

§Examples

use noyalib::{Error, Location};
let _e = Error::ParseWithLocation {
    message: "bad token".into(),
    location: Location::from_index("a: [", 3),
};

Fields

§message: String

The error message.

§Examples
use noyalib::{Error, Location};
let e = Error::ParseWithLocation {
    message: "bad".into(),
    location: Location::default(),
};
if let Error::ParseWithLocation { message, .. } = e {
    assert_eq!(message, "bad");
}
§location: Location

The location in the source where the error occurred.

§Examples
use noyalib::{Error, Location};
let e = Error::ParseWithLocation {
    message: "x".into(),
    location: Location::from_index("abc", 1),
};
if let Error::ParseWithLocation { location, .. } = e {
    assert_eq!(location.column(), 2);
}
§

Serialize(String)

Error during serialization.

§Examples

let _e = noyalib::Error::Serialize("bad value".into());
§

Deserialize(String)

Error during deserialization.

§Examples

let _e = noyalib::Error::Deserialize("type mismatch".into());
§

DeserializeWithLocation

Error during deserialization with location information.

§Examples

use noyalib::{Error, Location};
let _e = Error::DeserializeWithLocation {
    message: "expected int".into(),
    location: Location::default(),
};

Fields

§message: String

The error message.

§Examples
use noyalib::{Error, Location};
let e = Error::DeserializeWithLocation {
    message: "m".into(),
    location: Location::default(),
};
if let Error::DeserializeWithLocation { message, .. } = e {
    assert_eq!(message, "m");
}
§location: Location

The location in the source where the error occurred.

§Examples
use noyalib::{Error, Location};
let e = Error::DeserializeWithLocation {
    message: "m".into(),
    location: Location::from_index("ab", 1),
};
if let Error::DeserializeWithLocation { location, .. } = e {
    assert_eq!(location.column(), 2);
}
§

Io(Error)

Available on crate feature std only.

I/O error (requires std feature).

§Examples

let ioe = std::io::Error::new(std::io::ErrorKind::Other, "nope");
let _e = noyalib::Error::Io(ioe);
§

Custom(String)

Custom error message.

§Examples

let _e = noyalib::Error::Custom("whatever".into());
§

RecursionLimitExceeded

Error when recursion depth limit is exceeded.

§Examples

let _e = noyalib::Error::RecursionLimitExceeded { depth: 64 };

Fields

§depth: usize

The current depth.

§Examples
use noyalib::Error;
if let Error::RecursionLimitExceeded { depth } =
    (Error::RecursionLimitExceeded { depth: 10 })
{
    assert_eq!(depth, 10);
}
§

DuplicateKey(String)

Error when a duplicate key is encountered.

§Examples

let _e = noyalib::Error::DuplicateKey("name".into());
§

KeyCollision(String)

Two distinct-typed keys collapsed to the same string key.

The mapping key model is Mapping<String, Value>, so keys are stringified. Distinct YAML keys that share a spelling — e.g. the integer 1 and the string "1", or true and "true" — would silently overwrite each other, losing an entry. This is raised instead, carrying the collapsed string key. Unlike Self::DuplicateKey, it fires regardless of DuplicateKeyPolicy because it is data loss, not an authored duplicate.

§Examples

The construction shape:

let _e = noyalib::Error::KeyCollision("1".into());

Reproduces from real YAML. The integer key 1 and the string key "1" both stringify to "1", so parsing must refuse rather than silently drop the first entry:

use noyalib::{Error, Value, from_str};
let err = from_str::<Value>("1: a\n\"1\": b\n").unwrap_err();
assert!(matches!(err, Error::KeyCollision(_)));
§

RepetitionLimitExceeded

Repetition limit exceeded (security limit against billion-laughs).

§Examples

let _e = noyalib::Error::RepetitionLimitExceeded;
§

Budget(BudgetBreach)

A configurable parser budget was exceeded.

Carries a BudgetBreach identifying which limit fired, the configured cap, and (where meaningful) the observed value at the moment the cap tripped. Distinct from the older Error::RecursionLimitExceeded / Error::RepetitionLimitExceeded variants — those stay for backwards compatibility on the depth / alias-expansion limits; new budgets in the v0.0.2 expansion (max_events, max_nodes, max_total_scalar_bytes, max_documents, max_merge_keys, alias_anchor_ratio) all flow through Error::Budget.

§Examples

use noyalib::{BudgetBreach, Error};
let _e = Error::Budget(BudgetBreach::MaxDocuments {
    limit: 1_000,
    observed: 1_001,
});
§

UnknownAnchor(String)

Unknown anchor encountered.

§Examples

let _e = noyalib::Error::UnknownAnchor("missing".into());
§

UnknownAnchorAt

Unknown anchor encountered at a specific location.

§Examples

use noyalib::{Error, Location};
let _e = Error::UnknownAnchorAt {
    name: "x".into(),
    location: Location::default(),
    suggestion: None,
};

Fields

§name: String

The anchor name.

§Examples
use noyalib::{Error, Location};
let e = Error::UnknownAnchorAt {
    name: "x".into(),
    location: Location::default(),
    suggestion: None,
};
if let Error::UnknownAnchorAt { name, .. } = e {
    assert_eq!(name, "x");
}
§location: Location

The location where it was used.

§Examples
use noyalib::{Error, Location};
let e = Error::UnknownAnchorAt {
    name: "x".into(),
    location: Location::from_index("ab", 1),
    suggestion: None,
};
if let Error::UnknownAnchorAt { location, .. } = e {
    assert_eq!(location.column(), 2);
}
§suggestion: Option<(String, Location)>

Optional suggestion for a similar anchor.

§Examples
use noyalib::{Error, Location};
let e = Error::UnknownAnchorAt {
    name: "x".into(),
    location: Location::default(),
    suggestion: Some(("y".into(), Location::default())),
};
if let Error::UnknownAnchorAt { suggestion: Some((s, _)), .. } = e {
    assert_eq!(s, "y");
}
§

MissingField(String)

Missing field in a mapping.

§Examples

let _e = noyalib::Error::MissingField("name".into());
§

UnknownField(String)

Unknown field in a mapping (with deny_unknown_fields).

§Examples

let _e = noyalib::Error::UnknownField("extra".into());
§

ScalarInMergeElement

Scalar encountered where a mapping was expected during merge.

§Examples

let _e = noyalib::Error::ScalarInMergeElement;
§

SequenceInMergeElement

Sequence encountered where a mapping was expected during merge.

§Examples

let _e = noyalib::Error::SequenceInMergeElement;
§

TaggedInMerge

Tagged value encountered during merge.

§Examples

let _e = noyalib::Error::TaggedInMerge;
§

Invalid(String)

Generic invalid construct error.

§Examples

let _e = noyalib::Error::Invalid("bad construct".into());
§

TypeMismatch

A type mismatch error.

§Examples

let _e = noyalib::Error::TypeMismatch {
    expected: "integer",
    found: "string".into(),
};

Fields

§expected: &'static str

The expected type.

§Examples
use noyalib::Error;
let e = Error::TypeMismatch { expected: "int", found: "str".into() };
if let Error::TypeMismatch { expected, .. } = e {
    assert_eq!(expected, "int");
}
§found: String

The type that was actually found.

§Examples
use noyalib::Error;
let e = Error::TypeMismatch { expected: "int", found: "str".into() };
if let Error::TypeMismatch { found, .. } = e {
    assert_eq!(found, "str");
}
§

Shared(Arc<Error>)

Shared error instance (Arc-wrapped for cloning).

§Examples

use std::sync::Arc;
let _e = noyalib::Error::Shared(Arc::new(noyalib::Error::EndOfStream));
§

EndOfStream

End of stream reached unexpectedly.

§Examples

let _e = noyalib::Error::EndOfStream;
§

MoreThanOneDocument

More than one document found where one was expected.

§Examples

let _e = noyalib::Error::MoreThanOneDocument;
§

ScalarInMerge

Scalar in merge (legacy variant).

§Examples

let _e = noyalib::Error::ScalarInMerge;
§

EmptyTag

Empty tag encountered.

§Examples

let _e = noyalib::Error::EmptyTag;
§

FailedToParseNumber(String)

Failed to parse a number.

§Examples

let _e = noyalib::Error::FailedToParseNumber("not-a-number".into());
§

Message(String, Option<usize>)

A message error from Serde (compat variant).

§Examples

let _e = noyalib::Error::Message("oops".into(), Some(42));

Implementations§

Source§

impl Error

Source

pub fn render_with_formatter(&self, formatter: &dyn MessageFormatter) -> String

Render this error via a custom MessageFormatter.

Pairs with DefaultFormatter (developer-facing, verbatim) and UserFormatter (user-facing, simplified). Callers needing localisation or rich formatting plug in their own MessageFormatter impl.

§Examples
use noyalib::i18n::UserFormatter;
use noyalib::{from_str, Value};

let err = from_str::<Value>("a: [unclosed").unwrap_err();
let msg = err.render_with_formatter(&UserFormatter);
assert!(msg.contains("syntax error"));
Source§

impl Error

Source

pub fn location(&self) -> Option<Location>

Get the location of the error, if any.

§Examples
use noyalib::{from_str, Value};
let err = from_str::<Value>("a: [unclosed").unwrap_err();
let _ = err.location();
Source

pub fn kind(&self) -> ErrorKind

Coarse-grained classification for routing without matching every variant of the #[non_exhaustive] Error enum.

The mapping is stable across variant additions: new variants land under an existing ErrorKind whenever possible, so downstream match err.kind() sites keep compiling. When a new category is needed the enum grows (also #[non_exhaustive]).

§Examples
use noyalib::{from_str, ErrorKind, Value};

let syntax = from_str::<Value>("a: [unclosed").unwrap_err();
assert_eq!(syntax.kind(), ErrorKind::Syntax);

let collision = from_str::<Value>("1: a\n\"1\": b\n").unwrap_err();
assert_eq!(collision.kind(), ErrorKind::KeyCollision);
Source

pub fn format_with_source(&self, source: &str) -> String

Format the error with source context. If the error carries a source location and the line is in range, the output includes a line <n>:<col> prefix, the offending line, and a caret (^) pointing at the column. Out-of-range lines fall back to plain Display.

For rustc-style multi-line context with surrounding lines, use Self::format_with_source_radius.

§Examples
use noyalib::{from_str, Value};
let source = "a: [unclosed";
let err = from_str::<Value>(source).unwrap_err();
let formatted = err.format_with_source(source);
assert!(formatted.contains("error"));
Source

pub fn format_with_source_radius(&self, source: &str, radius: usize) -> String

Format the error with radius lines of context above and below the offending line — rustc-style. Each line gets a line number on the left; the caret line under the offending column is unnumbered. The output is byte-for-byte stable across minor releases (no terminal escape codes, no platform-conditional whitespace).

Out-of-range locations fall back to plain Display (no snippet) — same contract as Self::format_with_source.

§Examples
use noyalib::{from_str, Value};
// Indentation-mismatch error — carries a concrete `(line,
// column)` location, so the snippet renderer engages.
let source = "\
header: ok
service:
   nested: x
  bad: y
trailer: ok
";
let e = from_str::<Value>(source).unwrap_err();
let formatted = e.format_with_source_radius(source, 1);
// Output includes the offending line plus a single line
// of context above and below.
assert!(formatted.contains("|"));
assert!(formatted.contains("bad: y"));
Source

pub fn format_with_source_truncated( &self, source: &str, max_chars: usize, ) -> String

Format the error with source context, capped at max_chars ASCII characters — the bridged-channel-friendly variant of Self::format_with_source. Use when the diagnostic is destined for a Slack message, a Sentry tag, a structured log field, or any sink with a hard length budget.

§Truncation contract
  1. The output is plain ASCII (the renderer already emits no ANSI escapes, so this is a no-op for that axis).
  2. If the rendered string is <= max_chars, returns it unchanged.
  3. Otherwise truncates at a UTF-8 character boundary <= max_chars - 3 and appends an ... ellipsis so the final length is at most max_chars.
  4. max_chars smaller than 3 keeps as much of the prefix as fits and drops the ellipsis (so a max_chars = 2 yields exactly two characters of the message).
§Examples
use noyalib::{from_str, Value};
let source = "a: [unclosed";
let err = from_str::<Value>(source).unwrap_err();
let short = err.format_with_source_truncated(source, 60);
assert!(short.len() <= 60);
// Untrimmed output is the same as `format_with_source`:
let full = err.format_with_source(source);
let unbounded = err.format_with_source_truncated(source, full.len() + 100);
assert_eq!(unbounded, full);
Source

pub fn format_with_source_radius_truncated( &self, source: &str, radius: usize, max_chars: usize, ) -> String

Format the error with multi-line radius context, capped at max_chars. Same truncation contract as Self::format_with_source_truncated.

§Examples
use noyalib::{from_str, Value};
let source = "a:\n  b:\n    c: [unclosed";
let err = from_str::<Value>(source).unwrap_err();
let s = err.format_with_source_radius_truncated(source, 1, 80);
assert!(s.len() <= 80);
Source

pub fn into_shared(self) -> Arc<Self>

Convert the error into a shared Arc pointer. If the error is already Error::Shared, the inner Arc is reused without double-wrapping.

§Examples
let shared = noyalib::Error::EndOfStream.into_shared();
assert!(matches!(&*shared, noyalib::Error::EndOfStream));
Source

pub fn is_shared(&self) -> bool

Check if the error is a shared error.

§Examples
use std::sync::Arc;
let e = noyalib::Error::Shared(Arc::new(noyalib::Error::EndOfStream));
assert!(e.is_shared());
Source

pub fn as_inner(&self) -> Option<&Self>

Access the inner error if this is a shared error.

§Examples
use std::sync::Arc;
let e = noyalib::Error::Shared(Arc::new(noyalib::Error::EndOfStream));
assert!(e.as_inner().is_some());
Source

pub fn parse_at(message: impl Into<String>, source: &str, index: usize) -> Self

Create a new parse error at the given index.

§Examples
let e = noyalib::Error::parse_at("bad", "a: x", 3);
assert!(matches!(e, noyalib::Error::ParseWithLocation { .. }));
Source

pub fn deserialize_at( message: impl Into<String>, source: &str, index: usize, ) -> Self

Create a new deserialization error at the given index.

§Examples
let e = noyalib::Error::deserialize_at("bad", "a: x", 3);
assert!(matches!(e, noyalib::Error::DeserializeWithLocation { .. }));
Source

pub fn from_shared(arc: Arc<Error>) -> Error

Create a new error from a shared error pointer.

§Examples
use std::sync::Arc;
let e = noyalib::Error::from_shared(Arc::new(noyalib::Error::EndOfStream));
assert!(e.is_shared());
Source

pub fn render(&self, source: &str) -> String

Render the error in rustc-style with default options.

Equivalent to self.render_with_options(source, &RenderOptions::default()).

Issue #2 entry point — supersedes Self::format_with_source for new code; that method is preserved for backwards compatibility.

§Examples
use noyalib::{from_str, Value};
let source = "a:\n  b: 1\n   c: 2\n";  // misaligned indent
let err = from_str::<Value>(source).unwrap_err();
let rendered = err.render(source);
assert!(rendered.contains("error"));
Source

pub fn render_with_options(&self, source: &str, opts: &RenderOptions) -> String

Render the error with caller-controlled options.

RenderOptions::crop_radius sets how many lines of context surround the offending line; RenderOptions::color enables terminal ANSI colour codes. The default (RenderOptions::default()) is crop_radius = 2, color = false.

§Examples
use noyalib::{from_str, RenderOptions, Value};
let source = "a: [unclosed";
let err = from_str::<Value>(source).unwrap_err();
let opts = RenderOptions { crop_radius: 1, color: false };
let rendered = err.render_with_options(source, &opts);
assert!(rendered.contains("error"));

Trait Implementations§

Source§

impl Debug for Error

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Diagnostic for Error

Available on crate feature miette only.
Source§

fn code<'a>(&'a self) -> Option<Box<dyn Display + 'a>>

Unique diagnostic code that can be used to look up more information about this Diagnostic. Ideally also globally unique, and documented in the toplevel crate’s documentation for easy searching. Rust path format (foo::bar::baz) is recommended, but more classic codes like E0123 or enums will work just fine.
Source§

fn help<'a>(&'a self) -> Option<Box<dyn Display + 'a>>

Additional help text related to this Diagnostic. Do you have any advice for the poor soul who’s just run into this issue?
Source§

fn source_code(&self) -> Option<&dyn SourceCode>

Source code to apply this Diagnostic’s Diagnostic::labels to.
Source§

fn labels(&self) -> Option<Box<dyn Iterator<Item = LabeledSpan> + '_>>

Labels to apply to this Diagnostic’s Diagnostic::source_code
Source§

fn severity(&self) -> Option<Severity>

Diagnostic severity. This may be used by ReportHandlers to change the display format of this diagnostic. Read more
Source§

fn url<'a>(&'a self) -> Option<Box<dyn Display + 'a>>

URL to visit for a more detailed explanation/help about this Diagnostic.
Source§

fn related<'a>( &'a self, ) -> Option<Box<dyn Iterator<Item = &'a dyn Diagnostic> + 'a>>

Additional related Diagnostics.
Source§

fn diagnostic_source(&self) -> Option<&dyn Diagnostic>

The cause of the error.
Source§

impl Display for Error

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Error for Error

Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0:

use the Display impl or to_string()

1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl Error for Error

Source§

fn custom<T: Display>(msg: T) -> Self

Used when a Serialize implementation encounters any error while serializing a type. Read more
Source§

impl Error for Error

Source§

fn custom<T: Display>(msg: T) -> Self

Raised when there is general error when deserializing a type. Read more
Source§

fn missing_field(field: &'static str) -> Self

Raised when a Deserialize struct type expected to receive a required field with a particular name but that field was not present in the input.
Source§

fn unknown_field(field: &str, _expected: &'static [&'static str]) -> Self

Raised when a Deserialize struct type received a field with an unrecognized name.
Source§

fn invalid_type(unexp: Unexpected<'_>, exp: &dyn Expected) -> Self

Raised when a Deserialize receives a type different from what it was expecting. Read more
Source§

fn invalid_value(unexp: Unexpected<'_>, exp: &dyn Expected) -> Self

Raised when a Deserialize receives a value of the right type but that is wrong for some other reason. Read more
Source§

fn invalid_length(len: usize, exp: &dyn Expected) -> Self

Raised when deserializing a sequence or map and the input data contains too many or too few elements. Read more
Source§

fn unknown_variant(variant: &str, expected: &'static [&'static str]) -> Self

Raised when a Deserialize enum type received a variant with an unrecognized name.
Source§

fn duplicate_field(field: &'static str) -> Self

Raised when a Deserialize struct type received more than one of the same field.
Source§

impl From<Error> for Error

Available on crate feature std only.
Source§

fn from(e: Error) -> Self

Converts to this type from the input type.
Source§

impl<'de> IntoDeserializer<'de, Error> for &'de Value

Source§

type Deserializer = &'de Value

The type of the deserializer being converted into.
Source§

fn into_deserializer(self) -> Self::Deserializer

Convert this value into a deserializer.

Auto Trait Implementations§

§

impl !RefUnwindSafe for Error

§

impl !UnwindSafe for Error

§

impl Freeze for Error

§

impl Send for Error

§

impl Sync for Error

§

impl Unpin for Error

§

impl UnsafeUnpin for Error

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> Fmt for T
where T: Display,

Source§

fn fg<C>(self, color: C) -> Foreground<Self>
where C: Into<Option<Color>>, Self: Display,

Give this value the specified foreground colour.
Source§

fn bg<C>(self, color: C) -> Background<Self>
where C: Into<Option<Color>>, Self: Display,

Give this value the specified background colour.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<T> MaybeSendSync for T

Source§

impl<D> OwoColorize for D

Source§

fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>
where C: Color,

Set the foreground color generically Read more
Source§

fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>
where C: Color,

Set the background color generically. Read more
Source§

fn black(&self) -> FgColorDisplay<'_, Black, Self>

Change the foreground color to black
Source§

fn on_black(&self) -> BgColorDisplay<'_, Black, Self>

Change the background color to black
Source§

fn red(&self) -> FgColorDisplay<'_, Red, Self>

Change the foreground color to red
Source§

fn on_red(&self) -> BgColorDisplay<'_, Red, Self>

Change the background color to red
Source§

fn green(&self) -> FgColorDisplay<'_, Green, Self>

Change the foreground color to green
Source§

fn on_green(&self) -> BgColorDisplay<'_, Green, Self>

Change the background color to green
Source§

fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>

Change the foreground color to yellow
Source§

fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>

Change the background color to yellow
Source§

fn blue(&self) -> FgColorDisplay<'_, Blue, Self>

Change the foreground color to blue
Source§

fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>

Change the background color to blue
Source§

fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>

Change the foreground color to magenta
Source§

fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>

Change the background color to magenta
Source§

fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>

Change the foreground color to purple
Source§

fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>

Change the background color to purple
Source§

fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>

Change the foreground color to cyan
Source§

fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>

Change the background color to cyan
Source§

fn white(&self) -> FgColorDisplay<'_, White, Self>

Change the foreground color to white
Source§

fn on_white(&self) -> BgColorDisplay<'_, White, Self>

Change the background color to white
Source§

fn default_color(&self) -> FgColorDisplay<'_, Default, Self>

Change the foreground color to the terminal default
Source§

fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>

Change the background color to the terminal default
Source§

fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>

Change the foreground color to bright black
Source§

fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>

Change the background color to bright black
Source§

fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>

Change the foreground color to bright red
Source§

fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>

Change the background color to bright red
Source§

fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>

Change the foreground color to bright green
Source§

fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>

Change the background color to bright green
Source§

fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>

Change the foreground color to bright yellow
Source§

fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>

Change the background color to bright yellow
Source§

fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>

Change the foreground color to bright blue
Source§

fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>

Change the background color to bright blue
Source§

fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>

Change the foreground color to bright magenta
Source§

fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>

Change the background color to bright magenta
Source§

fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>

Change the foreground color to bright purple
Source§

fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>

Change the background color to bright purple
Source§

fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>

Change the foreground color to bright cyan
Source§

fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>

Change the background color to bright cyan
Source§

fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>

Change the foreground color to bright white
Source§

fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>

Change the background color to bright white
Source§

fn bold(&self) -> BoldDisplay<'_, Self>

Make the text bold
Source§

fn dimmed(&self) -> DimDisplay<'_, Self>

Make the text dim
Source§

fn italic(&self) -> ItalicDisplay<'_, Self>

Make the text italicized
Source§

fn underline(&self) -> UnderlineDisplay<'_, Self>

Make the text underlined
Make the text blink
Make the text blink (but fast!)
Source§

fn reversed(&self) -> ReversedDisplay<'_, Self>

Swap the foreground and background colors
Source§

fn hidden(&self) -> HiddenDisplay<'_, Self>

Hide the text
Source§

fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>

Cross out the text
Source§

fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>
where Color: DynColor,

Set the foreground color at runtime. Only use if you do not know which color will be used at compile-time. If the color is constant, use either OwoColorize::fg or a color-specific method, such as OwoColorize::green, Read more
Source§

fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>
where Color: DynColor,

Set the background color at runtime. Only use if you do not know what color to use at compile-time. If the color is constant, use either OwoColorize::bg or a color-specific method, such as OwoColorize::on_yellow, Read more
Source§

fn fg_rgb<const R: u8, const G: u8, const B: u8>( &self, ) -> FgColorDisplay<'_, CustomColor<R, G, B>, Self>

Set the foreground color to a specific RGB value.
Source§

fn bg_rgb<const R: u8, const G: u8, const B: u8>( &self, ) -> BgColorDisplay<'_, CustomColor<R, G, B>, Self>

Set the background color to a specific RGB value.
Source§

fn truecolor(&self, r: u8, g: u8, b: u8) -> FgDynColorDisplay<'_, Rgb, Self>

Sets the foreground color to an RGB value.
Source§

fn on_truecolor(&self, r: u8, g: u8, b: u8) -> BgDynColorDisplay<'_, Rgb, Self>

Sets the background color to an RGB value.
Source§

fn style(&self, style: Style) -> Styled<&Self>

Apply a runtime-determined style
Source§

impl<T> Paint for T
where T: ?Sized,

Source§

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 primary(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: Primary].

§Example
println!("{}", value.primary());
Source§

fn fixed(&self, color: u8) -> Painted<&T>

Returns self with the fg() set to [Color :: Fixed].

§Example
println!("{}", value.fixed(color));
Source§

fn rgb(&self, r: u8, g: u8, b: u8) -> Painted<&T>

Returns self with the fg() set to [Color :: Rgb].

§Example
println!("{}", value.rgb(r, g, b));
Source§

fn black(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: Black].

§Example
println!("{}", value.black());
Source§

fn red(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: Red].

§Example
println!("{}", value.red());
Source§

fn green(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: Green].

§Example
println!("{}", value.green());
Source§

fn yellow(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: Yellow].

§Example
println!("{}", value.yellow());
Source§

fn blue(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: Blue].

§Example
println!("{}", value.blue());
Source§

fn magenta(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: Magenta].

§Example
println!("{}", value.magenta());
Source§

fn cyan(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: Cyan].

§Example
println!("{}", value.cyan());
Source§

fn white(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: White].

§Example
println!("{}", value.white());
Source§

fn bright_black(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: BrightBlack].

§Example
println!("{}", value.bright_black());
Source§

fn bright_red(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: BrightRed].

§Example
println!("{}", value.bright_red());
Source§

fn bright_green(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: BrightGreen].

§Example
println!("{}", value.bright_green());
Source§

fn bright_yellow(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: BrightYellow].

§Example
println!("{}", value.bright_yellow());
Source§

fn bright_blue(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: BrightBlue].

§Example
println!("{}", value.bright_blue());
Source§

fn bright_magenta(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: BrightMagenta].

§Example
println!("{}", value.bright_magenta());
Source§

fn bright_cyan(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: BrightCyan].

§Example
println!("{}", value.bright_cyan());
Source§

fn bright_white(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: BrightWhite].

§Example
println!("{}", value.bright_white());
Source§

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>

Returns self with the bg() set to [Color :: Primary].

§Example
println!("{}", value.on_primary());
Source§

fn on_fixed(&self, color: u8) -> Painted<&T>

Returns self with the bg() set to [Color :: Fixed].

§Example
println!("{}", value.on_fixed(color));
Source§

fn on_rgb(&self, r: u8, g: u8, b: u8) -> Painted<&T>

Returns self with the bg() set to [Color :: Rgb].

§Example
println!("{}", value.on_rgb(r, g, b));
Source§

fn on_black(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: Black].

§Example
println!("{}", value.on_black());
Source§

fn on_red(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: Red].

§Example
println!("{}", value.on_red());
Source§

fn on_green(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: Green].

§Example
println!("{}", value.on_green());
Source§

fn on_yellow(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: Yellow].

§Example
println!("{}", value.on_yellow());
Source§

fn on_blue(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: Blue].

§Example
println!("{}", value.on_blue());
Source§

fn on_magenta(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: Magenta].

§Example
println!("{}", value.on_magenta());
Source§

fn on_cyan(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: Cyan].

§Example
println!("{}", value.on_cyan());
Source§

fn on_white(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: White].

§Example
println!("{}", value.on_white());
Source§

fn on_bright_black(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: BrightBlack].

§Example
println!("{}", value.on_bright_black());
Source§

fn on_bright_red(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: BrightRed].

§Example
println!("{}", value.on_bright_red());
Source§

fn on_bright_green(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: BrightGreen].

§Example
println!("{}", value.on_bright_green());
Source§

fn on_bright_yellow(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: BrightYellow].

§Example
println!("{}", value.on_bright_yellow());
Source§

fn on_bright_blue(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: BrightBlue].

§Example
println!("{}", value.on_bright_blue());
Source§

fn on_bright_magenta(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: BrightMagenta].

§Example
println!("{}", value.on_bright_magenta());
Source§

fn on_bright_cyan(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: BrightCyan].

§Example
println!("{}", value.on_bright_cyan());
Source§

fn on_bright_white(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: BrightWhite].

§Example
println!("{}", value.on_bright_white());
Source§

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 bold(&self) -> Painted<&T>

Returns self with the attr() set to [Attribute :: Bold].

§Example
println!("{}", value.bold());
Source§

fn dim(&self) -> Painted<&T>

Returns self with the attr() set to [Attribute :: Dim].

§Example
println!("{}", value.dim());
Source§

fn italic(&self) -> Painted<&T>

Returns self with the attr() set to [Attribute :: Italic].

§Example
println!("{}", value.italic());
Source§

fn underline(&self) -> Painted<&T>

Returns self with the attr() set to [Attribute :: Underline].

§Example
println!("{}", value.underline());

Returns self with the attr() set to [Attribute :: Blink].

§Example
println!("{}", value.blink());

Returns self with the attr() set to [Attribute :: RapidBlink].

§Example
println!("{}", value.rapid_blink());
Source§

fn invert(&self) -> Painted<&T>

Returns self with the attr() set to [Attribute :: Invert].

§Example
println!("{}", value.invert());
Source§

fn conceal(&self) -> Painted<&T>

Returns self with the attr() set to [Attribute :: Conceal].

§Example
println!("{}", value.conceal());
Source§

fn strike(&self) -> Painted<&T>

Returns self with the attr() set to [Attribute :: Strike].

§Example
println!("{}", value.strike());
Source§

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 mask(&self) -> Painted<&T>

Returns self with the quirk() set to [Quirk :: Mask].

§Example
println!("{}", value.mask());
Source§

fn wrap(&self) -> Painted<&T>

Returns self with the quirk() set to [Quirk :: Wrap].

§Example
println!("{}", value.wrap());
Source§

fn linger(&self) -> Painted<&T>

Returns self with the quirk() set to [Quirk :: Linger].

§Example
println!("{}", value.linger());
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.

Returns self with the quirk() set to [Quirk :: Clear].

§Example
println!("{}", value.clear());
Source§

fn resetting(&self) -> Painted<&T>

Returns self with the quirk() set to [Quirk :: Resetting].

§Example
println!("{}", value.resetting());
Source§

fn bright(&self) -> Painted<&T>

Returns self with the quirk() set to [Quirk :: Bright].

§Example
println!("{}", value.bright());
Source§

fn on_bright(&self) -> Painted<&T>

Returns self with the quirk() set to [Quirk :: OnBright].

§Example
println!("{}", value.on_bright());
Source§

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§

fn new(self) -> Painted<Self>
where Self: Sized,

Create a new Painted with a default Style. Read more
Source§

fn paint<S>(&self, style: S) -> Painted<&Self>
where S: Into<Style>,

Apply a style wholesale to self. Any previous style is replaced. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToCompactString for T
where T: Display,

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> ValidateIp for T
where T: ToString,

Source§

fn validate_ipv4(&self) -> bool

Validates whether the given string is an IP V4
Source§

fn validate_ipv6(&self) -> bool

Validates whether the given string is an IP V6
Source§

fn validate_ip(&self) -> bool

Validates whether the given string is an IP