Skip to main content

PreprocessorError

Enum PreprocessorError 

Source
pub enum PreprocessorError<'a> {
Show 27 variants Endif { endif_span: Span<'a>, }, NoEndif { cond_token: Token<'a>, cond_token_span: Span<'a>, }, Elsif { elsif_span: Span<'a>, }, Else { else_span: Span<'a>, }, EndKeywords { end_keywords_span: Span<'a>, }, NoEndKeywords { begin_keywords_span: Span<'a>, }, InvalidDefineParameter { other_token: Token<'a>, other_span: Span<'a>, }, InvalidDefineArgument { other_token: Token<'a>, other_span: Span<'a>, }, InvalidVersionSpecifier { invalid_version: Token<'a>, invalid_version_span: Span<'a>, }, IncompleteDirective { directive_span: Span<'a>, }, IncompleteDefine { other_token: Token<'a>, other_span: Span<'a>, }, UndefinedMacro { undefined_name: &'a str, undefined_span: Span<'a>, }, DuplicateMacroParameter { define_name: &'a str, param_name: &'a str, dup_span: Span<'a>, prev_span: Span<'a>, }, NoDefaultAfterDefault { default_param: &'a str, default_param_span: Span<'a>, non_default_param: &'a str, non_default_param_span: Span<'a>, }, NoMacroArguments { macro_name: &'a str, define_span: Span<'a>, use_span: Span<'a>, }, TooManyMacroArguments { macro_name: &'a str, define_span: Span<'a>, use_span: Span<'a>, expected: usize, found: usize, }, MissingMacroArgument { define_span: Span<'a>, use_span: Span<'a>, param_name: &'a str, }, InvalidIdentifierFormation { param_name: &'a str, arg_span: Span<'a>, }, InvalidRelativeTimescales { timescale_span: Span<'a>, }, IncompleteMacroWithToken { error_token: Token<'a>, error_span: Span<'a>, }, Include { include_path: &'a str, include_path_span: Span<'a>, read_err: ErrorKind, }, IncludeDepth { include_span: Span<'a>, }, VerboseError { err: VerboseError<'a>, }, NotPreviouslyDefinedMacro { macro_name: &'a str, macro_span: Span<'a>, }, RedefinedMacro { macro_name: &'a str, redef_span: Span<'a>, prev_def_span: Span<'a>, }, NewlineInDefine(Span<'a>), EndOfFunctionArgument(SpannedToken<'a>),
}
Expand description

An error encountered during preprocessing

As preprocessing can affect the interpretation of later source code, these errors are often irrecoverable

Errors marked with INTERNAL are meant for use inside the preprocessor for passing information, and should not be returned

Variants§

§

Endif

An `endif encountered outside a conditional preprocessor block

let source = "
`endif
";
let input = lex(source, "test.v").tokens();
let preprocess_result = preprocess(
    input,
    &mut state,
    &cache,
);
assert!(preprocess_result.is_err());
assert!(matches!(state.errors.first(), Some(PreprocessorError::Endif{ .. })));

Fields

§endif_span: Span<'a>

The Span of the `endif

§

NoEndif

No terminating `endif for a conditional preprocessor block

let source = "
`ifdef TEST
";
let input = lex(source, "test.v").tokens();
let preprocess_result = preprocess(
    input,
    &mut state,
    &cache,
);
assert!(preprocess_result.is_err());
assert!(matches!(state.errors.first(), Some(PreprocessorError::NoEndif{
    cond_token: Token::DirIfdef,
    ..
})));

Fields

§cond_token: Token<'a>

The conditional token (either Token::DirIfdef, Token::DirIfndef, Token::DirElsif, or Token::DirElse) with no matching `endif

§cond_token_span: Span<'a>

The Span of the conditional token

§

Elsif

An `elsif encountered outside a conditional preprocessor block

let source = "
`elsif
";
let input = lex(source, "test.v").tokens();
let preprocess_result = preprocess(
    input,
    &mut state,
    &cache,
);
assert!(preprocess_result.is_err());
assert!(matches!(state.errors.first(), Some(PreprocessorError::Elsif{ .. })));

Fields

§elsif_span: Span<'a>

The Span of the `elsif

§

Else

An `else encountered outside a conditional preprocessor block

let source = "
`else
";
let input = lex(source, "test.v").tokens();
let preprocess_result = preprocess(
    input,
    &mut state,
    &cache,
);
assert!(preprocess_result.is_err());
assert!(matches!(state.errors.first(), Some(PreprocessorError::Else{ .. })));

Fields

§else_span: Span<'a>

The Span of the `else

§

EndKeywords

An `end_keywords encountered outside a `begin_keywords block

let source = "
`end_keywords
";
let input = lex(source, "test.v").tokens();
let preprocess_result = preprocess(
    input,
    &mut state,
    &cache,
);
assert!(preprocess_result.is_err());
assert!(matches!(state.errors.first(), Some(PreprocessorError::EndKeywords{ .. })));

Fields

§end_keywords_span: Span<'a>

The Span of the `end_keywords

§

NoEndKeywords

No terminating `end_keywords for a `begin_keywords block

let source = "
`begin_keywords \"1800-2009\"
";
let input = lex(source, "test.v").tokens();
let preprocess_result = preprocess(
    input,
    &mut state,
    &cache,
);
assert!(preprocess_result.is_err());
assert!(matches!(state.errors.first(), Some(PreprocessorError::NoEndKeywords{ .. })));

Fields

§begin_keywords_span: Span<'a>

The Span of the unterminated `begin_keywords

§

InvalidDefineParameter

A missing parameter in a `define function declaration where one is expected

let source = "
`define TEST()
";
let input = lex(source, "test.v").tokens();
let preprocess_result = preprocess(
    input,
    &mut state,
    &cache,
);
assert!(preprocess_result.is_err());
assert!(matches!(state.errors.first(), Some(PreprocessorError::InvalidDefineParameter{
    other_token: Token::EParen,
    ..
})));

Fields

§other_token: Token<'a>

The Token found instead of the `define parameter

§other_span: Span<'a>

The Span of the token found instead

§

InvalidDefineArgument

A missing or invalid argument specification in a `define function

let source = "
`define TEST(a, b c)
";
let input = lex(source, "test.v").tokens();
let preprocess_result = preprocess(
    input,
    &mut state,
    &cache,
);
assert!(preprocess_result.is_err());
assert!(matches!(state.errors.first(), Some(PreprocessorError::InvalidDefineArgument{
    other_token: Token::SimpleIdentifier("c"),
    ..
})));

Fields

§other_token: Token<'a>

The Token found instead of the valid `define argument

§other_span: Span<'a>

The Span of the token found instead

§

InvalidVersionSpecifier

An invalid version specifier for a `begin_keywords directive

let source = "
`begin_keywords \"MyVersion\"
";
let input = lex(source, "test.v").tokens();
let preprocess_result = preprocess(
    input,
    &mut state,
    &cache,
);
assert!(preprocess_result.is_err());
assert!(matches!(state.errors.first(), Some(PreprocessorError::InvalidVersionSpecifier{
    invalid_version: Token::StringLiteral("MyVersion"),
    ..
})));

Fields

§invalid_version: Token<'a>

The Token provided instead of a valid version specifier

If the token is a Token::StringLiteral, the string isn’t a version recognized by 1800-2023

§invalid_version_span: Span<'a>

The Span of the invalid version specifier

§

IncompleteDirective

A directive that doesn’t have all of the required components

In general, PreprocessorError::VerboseError is preferred, but may not be suitable due to a lack of subsequent tokens

let source = "`line";
let input = lex(source, "test.v").tokens();
let preprocess_result = preprocess(
    input,
    &mut state,
    &cache,
);
assert!(preprocess_result.is_err());
assert!(matches!(state.errors.first(), Some(PreprocessorError::IncompleteDirective{ .. })));

Fields

§directive_span: Span<'a>

The Span of the incomplete preprocessor directive

This is usually the primary directive, but can be other more indicative tokens as well, such as an unmatched opening parenthesis

§

IncompleteDefine

An incomplete preprocessor definition, specifically with function macro arguments

let source = "
`define TEST(
";
let input = lex(source, "test.v").tokens();
let preprocess_result = preprocess(
    input,
    &mut state,
    &cache,
);
assert!(preprocess_result.is_err());
assert!(matches!(state.errors.first(), Some(PreprocessorError::IncompleteDefine{
    other_token: Token::Paren,
    ..
})));

Fields

§other_token: Token<'a>

If known, the Token found instead of a valid function macro argument specification

In the case that the token wasn’t tracked, the opening Token::Paren is referenced instead

§other_span: Span<'a>

The Span of the token found instead

§

UndefinedMacro

Use of a text macro that wasn’t previously defined

let source = "
`TEST
";
let input = lex(source, "test.v").tokens();
let preprocess_result = preprocess(
    input,
    &mut state,
    &cache,
);
assert!(preprocess_result.is_err());
assert!(matches!(state.errors.first(), Some(PreprocessorError::UndefinedMacro{
    undefined_name: "TEST",
    ..
})));

Fields

§undefined_name: &'a str

The name of the undefined macro

§undefined_span: Span<'a>

The Span of the undefined macro

§

DuplicateMacroParameter

Specifying a macro parameter that was already specified

let source = "
`define TEST(a, b, a) a + b
";
let input = lex(source, "test.v").tokens();
let preprocess_result = preprocess(
    input,
    &mut state,
    &cache,
);
assert!(preprocess_result.is_err());
assert!(matches!(state.errors.first(), Some(PreprocessorError::DuplicateMacroParameter{
    define_name: "TEST",
    param_name: "a",
    ..
})));

Fields

§define_name: &'a str

The name of the macro for which duplicate parameters were specified

§param_name: &'a str

The name of the parameter that was specified multiple times

§dup_span: Span<'a>

The Span of the duplicate specification

§prev_span: Span<'a>

The Span of the previous/original specification

§

NoDefaultAfterDefault

Attempting to have a macro parameter with no default value after one that does

let source = "
`define TEST(a = 1, b) a + b
";
let input = lex(source, "test.v").tokens();
let preprocess_result = preprocess(
    input,
    &mut state,
    &cache,
);
assert!(preprocess_result.is_err());
assert!(matches!(state.errors.first(), Some(PreprocessorError::NoDefaultAfterDefault{
    default_param: "a",
    non_default_param: "b",
    ..
})));

Fields

§default_param: &'a str

The name of the previously-specified default parameter

§default_param_span: Span<'a>

The Span of the previously-specified default parameter

§non_default_param: &'a str

The name of the non-default parameter

§non_default_param_span: Span<'a>

The Span of the non-default parameter

§

NoMacroArguments

Specifying no arguments for a macro function that takes arguments

let source = "
`define TEST(a, b) a + b
`TEST
";
let input = lex(source, "test.v").tokens();
let preprocess_result = preprocess(
    input,
    &mut state,
    &cache,
);
assert!(preprocess_result.is_err());
assert!(matches!(state.errors.first(), Some(PreprocessorError::NoMacroArguments{
    macro_name: "TEST",
    ..
})));

Fields

§macro_name: &'a str

The name of the macro

§define_span: Span<'a>

The Span of the macro definition (with arguments)

§use_span: Span<'a>

The Span where the macro was used with no arguments

§

TooManyMacroArguments

Specifying too many arguments for a macro function

let source = "
`define TEST(a, b) a + b
`TEST(1, 2, 3)
";
let input = lex(source, "test.v").tokens();
let preprocess_result = preprocess(
    input,
    &mut state,
    &cache,
);
assert!(preprocess_result.is_err());
assert!(matches!(state.errors.first(), Some(PreprocessorError::TooManyMacroArguments{
    macro_name: "TEST",
    expected: 2,
    found: 3,
    ..
})));

Fields

§macro_name: &'a str

The name of the macro

§define_span: Span<'a>

The Span of the macro definition

§use_span: Span<'a>

The Span where the macro was used with too many arguments

§expected: usize

How many arguments were expected

§found: usize

How many arguments were found

§

MissingMacroArgument

Missing an argument in a macro function use

let source = "
`define TEST(a, b) a + b
`TEST(1)
";
let input = lex(source, "test.v").tokens();
let preprocess_result = preprocess(
    input,
    &mut state,
    &cache,
);
assert!(preprocess_result.is_err());
assert!(matches!(state.errors.first(), Some(PreprocessorError::MissingMacroArgument{
    param_name: "b",
    ..
})));

Fields

§define_span: Span<'a>

The Span of the macro definition

§use_span: Span<'a>

The Span where the macro was used with a missing argument

§param_name: &'a str

The name of the missing parameter

§

InvalidIdentifierFormation

An invalid preprocessor identifier specification

let source = "
`define TEST(a, b) a``_with_``b
`TEST(\"one\", \"two\")
";
let input = lex(source, "test.v").tokens();
let preprocess_result = preprocess(
    input,
    &mut state,
    &cache,
);
assert!(preprocess_result.is_err());
assert!(matches!(state.errors.first(), Some(PreprocessorError::InvalidIdentifierFormation{
    param_name: "a",
    ..
})));

Fields

§param_name: &'a str

The name of the parameter used in a preprocessor identifier

§arg_span: Span<'a>

The Span of the invalid argument

§

InvalidRelativeTimescales

A precision that is less precise than the unit in a `timescale directive

let source = "
`timescale 100 fs / 1 s
";
let input = lex(source, "test.v").tokens();
let preprocess_result = preprocess(
    input,
    &mut state,
    &cache,
);
assert!(preprocess_result.is_err());
assert!(matches!(state.errors.first(), Some(PreprocessorError::InvalidRelativeTimescales{ .. })));

Fields

§timescale_span: Span<'a>

The Span of the `timescale directive

§

IncompleteMacroWithToken

An incomplete macro due to mismatching grouping tokens ([], (), or {})

let source = "
`define TEST(a, b) a + b
`TEST(a = 1, b = 2])
";
let input = lex(source, "test.v").tokens();
let preprocess_result = preprocess(
    input,
    &mut state,
    &cache,
);
assert!(preprocess_result.is_err());
assert!(matches!(state.errors.first(), Some(PreprocessorError::IncompleteMacroWithToken{
    error_token: Token::EBracket,
    ..
})));

Fields

§error_token: Token<'a>

The error-causing Token (either Token::EParen, Token::EBracket, or Token::EBrace)

§error_span: Span<'a>

The error-causing Span

§

Include

An error reading a file specified by an `include macro

let source = "
`include \"other.v\"
";
let input = lex(source, "test.v").tokens();
let preprocess_result = preprocess(
    input,
    &mut state,
    &cache,
);
assert!(preprocess_result.is_err());
assert!(matches!(state.errors.first(), Some(PreprocessorError::Include{
    include_path: "other.v",
    ..
})));

Fields

§include_path: &'a str

The path for the `include directive

§include_path_span: Span<'a>

The Span of the include path

§read_err: ErrorKind

The io::ErrorKind raised when attempting to read the file

§

IncludeDepth

The maximum include depth was hit, likely as a result of a self-referential `include sequence

let source = "
`include \"test.v\"
";
state.retain_file(
    "test.v".to_string(),
    source.to_string(),
    &cache,
);
let input = lex(source, "test.v").tokens();
let preprocess_result = preprocess(
    input,
    &mut state,
    &cache,
);
assert!(preprocess_result.is_err());
assert!(matches!(state.errors.first(), Some(PreprocessorError::IncludeDepth{ .. })));

Fields

§include_span: Span<'a>

The Span of the `include directive that exceeded the limit

§

VerboseError

A VerboseError detailing the expected and found tokens, for a case not covered above

This is most commonly used when we can provide the user with a bit more context

let source = "
`line
";
let input = lex(source, "test.v").tokens();
let preprocess_result = preprocess(
    input,
    &mut state,
    &cache,
);
// Expects a line number
assert!(preprocess_result.is_err());
assert!(matches!(state.errors.first(), Some(PreprocessorError::VerboseError{
    err: VerboseError{
        found: Some(Token::Newline),
        ..
    }
})));

Fields

§err: VerboseError<'a>

The VerboseError for the preprocessor error

§

NotPreviouslyDefinedMacro

Attempted to `undef a macro that had no previous definition

let source = "
`undef TEST
";
let input = lex(source, "test.v").tokens();
let preprocess_result = preprocess(
    input,
    &mut state,
    &cache,
);
assert!(preprocess_result.is_ok());
assert!(matches!(state.errors.first(), Some(PreprocessorError::NotPreviouslyDefinedMacro{
    macro_name: "TEST",
    ..
})))

Fields

§macro_name: &'a str

The name that wasn’t previously defined

§macro_span: Span<'a>

The Span where the not-previously-defined name was specified

§

RedefinedMacro

A redefinition of a text macro that was previously defined

let source = "
`define TEST definition_one
`define TEST definition_two
";
let input = lex(source, "test.v").tokens();
let preprocess_result = preprocess(
    input,
    &mut state,
    &cache,
);
assert!(preprocess_result.is_ok());
assert!(matches!(state.errors.first(), Some(PreprocessorError::RedefinedMacro{
    macro_name: "TEST",
    ..
})))

Fields

§macro_name: &'a str

The name of the macro being redefined

§redef_span: Span<'a>

The Span of the redefinition

§prev_def_span: Span<'a>

The Span where the macro was previously defined

§

NewlineInDefine(Span<'a>)

INTERNAL: A newline encountered in a `define directive

§

EndOfFunctionArgument(SpannedToken<'a>)

INTERNAL: The end of a function argument was encountered

Implementations§

Source§

impl<'a> PreprocessorError<'a>

Source

pub fn is_warning(&self) -> bool

Whether the given PreprocessorError is just a warning

Warnings reflect an irregularity in the source code, but are still well-defined and allow preprocessing to continue

Trait Implementations§

Source§

impl<'a> Clone for PreprocessorError<'a>

Source§

fn clone(&self) -> PreprocessorError<'a>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for PreprocessorError<'a>

Source§

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

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

impl<'s> From<&PreprocessorError<'s>> for Report

Source§

fn from(s: &PreprocessorError<'s>) -> Self

Converts to this type from the input type.
Source§

impl<'a> PartialEq for PreprocessorError<'a>

Source§

fn eq(&self, other: &PreprocessorError<'a>) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<'a> StructuralPartialEq for PreprocessorError<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for PreprocessorError<'a>

§

impl<'a> RefUnwindSafe for PreprocessorError<'a>

§

impl<'a> Send for PreprocessorError<'a>

§

impl<'a> Sync for PreprocessorError<'a>

§

impl<'a> Unpin for PreprocessorError<'a>

§

impl<'a> UnsafeUnpin for PreprocessorError<'a>

§

impl<'a> UnwindSafe for PreprocessorError<'a>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
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> 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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.