Skip to main content

TsExpr

Enum TsExpr 

Source
pub enum TsExpr {
Show 34 variants Ident(String), VerbatimExpr(String, VerbatimOrigin), RawUsing(String, Vec<String>), Member { object: Box<TsExpr>, property: String, }, OptionalMember { object: Box<TsExpr>, property: String, }, TypeApp { callee: Box<TsExpr>, type_args: Vec<TsType>, }, DefaultIife { name: String, default: Box<TsExpr>, return_type: TsType, body: Vec<TsStmt>, }, LinesArray(Vec<TsExpr>), Index { object: Box<TsExpr>, index: Box<TsExpr>, }, OptionalIndex { object: Box<TsExpr>, index: Box<TsExpr>, }, Arrow { params: Vec<TsParam>, is_async: bool, generics: Vec<String>, return_type: Option<TsType>, body: Box<TsArrowBody>, }, Call { callee: Box<TsExpr>, args: Vec<TsExpr>, }, New { callee: Box<TsExpr>, args: Vec<TsExpr>, }, Object { entries: Vec<TsObjectEntry>, multiline: bool, end_span: Option<Span>, }, Array { items: Vec<TsExpr>, multiline: bool, }, TemplateLit { parts: Vec<String>, exprs: Vec<TsExpr>, }, Await(Box<TsExpr>), As { expr: Box<TsExpr>, ty: TsType, }, AsConst(Box<TsExpr>), Unary { op: TsUnaryOp, expr: Box<TsExpr>, }, Binary { op: TsBinaryOp, left: Box<TsExpr>, right: Box<TsExpr>, }, Conditional { test: Box<TsExpr>, consequent: Box<TsExpr>, alternate: Box<TsExpr>, }, MultilineConditional { test: Box<TsExpr>, consequent: Box<TsExpr>, alternate: Box<TsExpr>, }, Paren(Box<TsExpr>), Spread(Box<TsExpr>), NonNull(Box<TsExpr>), Assign { target: Box<TsExpr>, value: Box<TsExpr>, }, AddAssign { target: Box<TsExpr>, value: Box<TsExpr>, }, NullishAssign { target: Box<TsExpr>, value: Box<TsExpr>, }, Lit(TsLit), Sequence(Vec<TsExpr>), OptionalCall { callee: Box<TsExpr>, args: Vec<TsExpr>, }, Function { is_async: bool, is_generator: bool, params: Vec<TsParam>, return_type: Option<TsType>, body: Vec<TsStmt>, }, Yield(Box<TsExpr>),
}
Expand description

An expression. Only the shapes events_fanout.rs concretely uses (Decision B) — not the reference sketch’s full TsExpr list (Arrow, Cond, TemplateLit, Spread are all unused in the grounding file and deliberately not built here). Arc C slice 3 (#1321, workers.rs) adds Arrow, OptionalMember/OptionalIndex (Decision A, gaps 3/4) — this slice’s own real, grounded needs.

Variants§

§

Ident(String)

A real identifier — the only content this variant is for. #1539 (review of design/reviews/2026-08-30-post-restructuring-review.md Part 3/Part 5 §1): before this doc existed, bynk-emit also smuggled non-identifier text through it at 15 call sites in emit.rs alone — a quoted string literal, this.<method> member access, a complete !(<pred>) unary expression — an untagged Verbatim-shaped escape hatch TsStmt::verbatim’s own doc already named the concern for (Q2’s “makes the ratchet a compile-time construct, not a grep”), just with no tag and no probe watching it. Every one of those call sites now either builds the matching real node (Lit(TsLit::Str), Member, Unary) or routes through TsExpr::VerbatimExpr instead — this variant no longer holds anything but a genuine identifier.

§

VerbatimExpr(String, VerbatimOrigin)

A residual, not-yet-converted expression carrying a VerbatimOrigin tag — TsStmt::verbatim’s own discipline, closed for expressions too (#1539). Printed exactly as TsExpr::Ident always was (raw text, no escaping of its own — the caller is responsible for producing valid, already-escaped TypeScript, the same contract TsStmt::verbatim’s own text carries), but now visible to crate::verbatim_violations and xtask’s own verbatim_origins/ verbatim_sites gated probes, which had nothing to watch at the expression level before this variant existed. What ends up here after #1539’s own conversion pass: a generic-typed method/constructor callee (Call/New have no type_args field), a block-bodied IIFE with no matching TsArrowBody shape, and a pred_condition_and_ message-style message that is already pre-escaped or unescaped by contract (a second escaping pass through TsLit::Str would corrupt it) — none of these has a real node to convert to without expanding this crate’s own type algebra well past what #1539 asks for.

§

RawUsing(String, Vec<String>)

Expression text that also declares the names it uses (1A.36b-1): the expression twin of TsStmt::raw_using. text prints exactly as an TsExpr::Ident’s does and is bracketed as one is, so a caller whose expression is printed nodes joined into one line (a form no node can hold) keeps it, and names are the identifiers the text spells without declaring, which name_closure counts as uses. The names are taken from the nodes the text was printed from (unbound_names_in over them), never scanned out of the text.

§

Member

object.property.

Fields

§object: Box<TsExpr>
§property: String
§

OptionalMember

object?.property — the optional-chaining form of TsExpr::Member. A distinct variant, not an optional: bool flag on Member itself (#1321’s own Decision A, gap 4, left the mechanism to the implementation): a flag would touch every one of Member’s already-many real call sites (events_fanout.rs, this crate’s own printer tests) that never need one, where a separate variant touches none of them — narrower, matching this track’s own repeated “smallest correct scope” judgment. workers.rs’s own secret-probe idiom (emit_websocket_upgrade/emit_http_wrapper/ emit_secret_lookup, three identical real sites) is the only grounding.

Fields

§object: Box<TsExpr>
§property: String
§

TypeApp

callee<A, B>: a TypeScript instantiation expression (1A.20, #3721, Decision A). A generic call is Call { callee: TypeApp { .. }, args } (f<T>(a)) and a generic constructor New { callee: TypeApp { .. }, args } (new C<T>(a)), so Call and New stay as they are. Postfix like TsExpr::Member: the callee is bracketed under the rule Call’s own callee uses.

Valid only as the callee of a Call or a New: f<T>.x is TS1477 and f<> is a syntax error, so type_args must not be empty and the printer asserts it, as it does for TsExpr::Spread.

Fields

§callee: Box<TsExpr>
§type_args: Vec<TsType>
§

DefaultIife

((name = default): ret => { body })(): an immediately invoked arrow whose one untyped parameter takes its value from a default, which JS evaluates at call time, before the body runs (1A.21, #3722). Json.encodePlain evaluates its argument this way before the body raises a flag. A node of its own, rather than a default on TsParam, so the 189 parameter literals stay as they are. Prints as a call, so it takes the brackets a call takes.

Fields

§name: String
§default: Box<TsExpr>
§return_type: TsType
§body: Vec<TsStmt>
§

LinesArray(Vec<TsExpr>)

An array printed one item per line, each with a trailing comma and the closing bracket back at the enclosing depth, wherever it sits (1A.14: par’s await __bynkSettleAll([…])). Unlike TsExpr::Array with multiline: true, which breaks only as a whole statement’s initialiser, this breaks as a call argument too.

§

Index

object[index].

Fields

§object: Box<TsExpr>
§index: Box<TsExpr>
§

OptionalIndex

object?.[index] — the optional-chaining form of TsExpr::Index, the same real grounding and the same “separate variant, not a flag” reasoning as TsExpr::OptionalMember.

Fields

§object: Box<TsExpr>
§index: Box<TsExpr>
§

Arrow

(params) => body (is_async: false) or async (params) => body (is_async: true) — an arrow function, expression- or block-bodied (see TsArrowBody). is_async added by #1327: emit_composition_root’s own __eventsDispatch closure (async (events: Array<...>) => {...}) is the first real Arrow site that’s async — mirrors TsDecl::Function’s own is_async field (#1325), added for the same reason. generics/return_type added by #1339: emit_sum_type’s own generic payload-constructor arrows (<T>(name: T): Sum<T> => (...)) need both — bare generic names only (empty for every non-generic site, the overwhelming majority), matching TsObjectEntry::Method.generics’s own (#1337) identical convention; return_type mirrors TsDecl::Function.return_type’s own existing Option<TsType> shape — a real gap the accepted proposal’s own grounding named generics for but missed: every one of this file’s own real generic-payload arrows carries an explicit return-type annotation the arrow itself owns (: {name}{params}), not something the body’s own type alone determines.

body’s type became TsArrowBody (#1435, Arc E slice 1): from P7.8 through #1434 this field was a bare Box<TsExpr> — expression- bodied only, “extend narrowly” (the same posture TsBinaryOp takes for its own operator table), since every real site up to and including #1339’s generic payload-constructor arrows had an expression body. serialisation.rs’s serialise_field_expr_wire (bynk-emit) is the first real site that doesn’t: its Float non-finite guard is a genuine statement-bodied IIFE (((v: number) => { if (!Number.isFinite(v)) throw new Error(...); return v as JsonValue; })(value)), not reducible to one expression. Widening the existing field (TsArrowBody::Expr(Box<TsExpr>) | TsArrowBody::Block(Vec<TsStmt>)) rather than adding a second sibling TsExpr variant matches this file’s own repeated “extend the existing variant when every real site still needs the same node kind, only the body shape differs” precedent (TsObjectEntry::Method.inline, #1337) — every prior Arrow construction site across the workspace wraps its already-correct expression body in TsArrowBody::Expr(..), a mechanical change with no behavior difference.

Fields

§params: Vec<TsParam>
§is_async: bool
§generics: Vec<String>
§return_type: Option<TsType>
§

Call

Fields

§callee: Box<TsExpr>
§args: Vec<TsExpr>
§

New

Fields

§callee: Box<TsExpr>
§args: Vec<TsExpr>
§

Object

A value object literal, e.g. { status: 204 } — comma-separated. multiline: false (the ordinary case, via TsExpr::object) always prints on one line, matching TsType::Object’s own (semicolon-separated) single-line convention for the type-position shape. multiline: true (via TsExpr::multiline_object) is a real, grounded gap found implementing Arc C’s first slice (#1317): events_fanout.rs’s own __eventRoutes table is a top-level const initializer with one entry per line, each with its own trailing comma, closing brace at the statement’s own indent — TypeScript’s ordinary multi-line object-literal convention, which nothing in this crate could represent before this addition. Only statement/declaration-level renderers (which already carry depth) can render this correctly — printer/multiline.rs’s own render_stmt_level_ expr, and (#1355) render_multiline_object_entry‘s own Prop arm, for a multiline: true object nested one level inside ANOTHER multiline object as one of its own entries’ values — emit_messages_bundle’s own real doubly-nested { locale: { code: expr, ... }, ... } table. A multiline: true object nested any OTHER way (an array element, a call argument, a Prop’s value inside a non-multiline object, …) still renders via the ordinary depth-unaware render_expr recursion, which cannot honour multiline — not reachable from any real bynk-emit call site today, but worth knowing before nesting one that way.

end_span (1A.32a) is only read for multiline: true: the source span the closing } line maps to, so what follows the last entry belongs to the declaration the object initialises rather than to the last entry’s final body line. None records nothing. Build one with TsExpr::multiline_object_ending_at.

Fields

§multiline: bool
§end_span: Option<Span>
§

Array

An array literal, e.g. [{ binding: "x", service: "y" }]. multiline: false (the ordinary case, via TsExpr::array) always prints on one line, comma-separated — every real site before this slice. multiline: true (via TsExpr::multiline_array) is #1325’s own real gap: emit_test_main’s own modules array (one { name, run } entry per test, one per line, each with its own trailing comma, closing ] at the statement’s own indent) — the exact same shape TsExpr::Object’s own multiline field already represents for object literals, just for an array. Same reachability boundary as Object’s own multiline field (see its own doc, updated by #1355): render_stmt_level_expr and render_multiline_object_ entry’s own Prop arm both honour it; nested any other way, a multiline: true array falls back to single-line via the ordinary depth-unaware render_expr recursion.

Fields

§items: Vec<TsExpr>
§multiline: bool
§

TemplateLit

`text${expr}more text` — a template literal. parts.len() is always exprs.len() + 1 (parts[0] before the first substitution, parts[i+1] after exprs[i], …). #1325’s own real, first grounding for this shape (bynk-ts’s own module doc named TemplateLit explicitly “unused in the grounding file” until now): emit_test_main’s own `${m.name}:`/`${passed} passed, ${failed} failed.` lines.

parts are printed verbatim — the printer applies no escaping of its own. The same “the field is already a raw-text slot” reasoning TsDecl::Import’s own names field doc already uses, not a new pattern: emit_test_main’s own two real ✓/✗ substitution lines embed a literal ✓/✗ JS unicode escape as pre-formed ASCII text (six literal characters, not the actual glyph) — an escaper mirroring TsLit::Str’s own (which escapes every \ it sees) would double that literal backslash into \\u2713, corrupting the exact byte-golden output this slice must match. Every real part in emit_test_main is static, compiler-authored text (never Bynk user data), so there is no real content this boundary loses safety on today — a future caller passing untrusted/dynamic text into parts is responsible for pre-escaping backtick/${/\ itself before constructing one.

Fields

§parts: Vec<String>
§exprs: Vec<TsExpr>
§

Await(Box<TsExpr>)

§

As

expr as ty.

Fields

§expr: Box<TsExpr>
§

AsConst(Box<TsExpr>)

expr as const: a const assertion, which keeps a literal’s own type ({ tag: "Some" as const }). It is not an As over a type named const: const is a keyword here, not a type.

§

Unary

Fields

§expr: Box<TsExpr>
§

Binary

Fields

§left: Box<TsExpr>
§right: Box<TsExpr>
§

Conditional

test ? consequent : alternate — #1323’s own real gap: method === "HEAD" ? headResponse(__response) : __response (once per GET route) and method === "OPTIONS" ? 204 : 405 (the method-fallthrough path). The lowest-precedence expression form after Arrow — needs the same parenthesization-rule coverage Arrow got in review of #1322 (needs_parens_as_operand/render_binary_operand/As’s own local rule), added proactively in this same slice rather than left for a review round to re-find.

Fields

§test: Box<TsExpr>
§consequent: Box<TsExpr>
§alternate: Box<TsExpr>
§

MultilineConditional

TsExpr::Conditional broken over three lines (1A.38a): the test, then ? consequent and : alternate each on a line of their own, one level deeper than the statement that holds it. A separate variant rather than a multiline field, so none of the existing Conditional constructions changes; it takes every precedence and parenthesisation rule Conditional does. Build it with TsExpr::multiline_conditional.

Fields

§test: Box<TsExpr>
§consequent: Box<TsExpr>
§alternate: Box<TsExpr>
§

Paren(Box<TsExpr>)

An explicit, printer-preserved parenthesization — distinct from every other variant’s own precedence-derived parens (render_operand/ render_binary_operand), which the printer adds or omits based on what the wrapped expression is. Paren instead always prints (<inner>) regardless of inner’s own shape or precedence. #1323’s own real, narrow need: workers_entry.rs’s CORS-preflight guard wraps its own path-match condition in unconditional parens (&& ({cond})) even when cond reduces to a single equality check with no operator lower-precedence than the outer && — a real case the precedence-derived rules correctly do not parenthesize (they’re answering “is this needed for correctness”, not “did the source always write parens here”). Not a general escape hatch: every other real site in this file’s own content still goes through the ordinary precedence machinery unchanged.

§

Spread(Box<TsExpr>)

...x, a spread element (1A.18a, #3719). Legal only as an item of TsExpr::Array or an argument of TsExpr::Call (1A.32b), where it prints ... then its operand with no brackets of its own: a spread operand is an assignment expression, so anything but a comma expression (which TsExpr cannot build) stands there as it is. A new variant rather than an item type on Array, which every existing array site would then have to change.

§

NonNull(Box<TsExpr>)

operand!, the non-null assertion (1A.23, #3724): the persisted-store arms read a modify callback’s current value, typed V | undefined, as a V once the key is known present. Postfix like TsExpr::Member: the operand is bracketed under the rule a member’s object uses.

§

Assign

target = value, an assignment expression (1A.18b, #3719): the one place a value is assigned and used at once, (__h[__k] = __h[__k] ?? []) .push(__u). An assignment as a whole statement is TsStmtKind::Assign. The printer brackets it wherever it is an operand; a builder that wants the brackets for readability, as that example does, adds an explicit TsExpr::Paren.

Fields

§target: Box<TsExpr>
§value: Box<TsExpr>
§

AddAssign

target += value (1A.18b, #3719), the list kernel’s average sum. A sibling of TsExpr::Assign, used as an expression statement.

Fields

§target: Box<TsExpr>
§value: Box<TsExpr>
§

NullishAssign

target ??= value (1A.36b-1): assigns only when the target is null or undefined, and yields the target’s value. A sibling of TsExpr::Assign that a cached constant’s accessor is built from, bracketed as it is.

Fields

§target: Box<TsExpr>
§value: Box<TsExpr>
§

Lit(TsLit)

§

Sequence(Vec<TsExpr>)

(a, b, c) (1A.35a part B): a comma expression, which evaluates each item in order and yields the last. It prints with its own brackets, so it is safe in any operand or argument position. Needs at least two items.

§

OptionalCall

callee?.(args) (1A.35a part B): an optional call, which yields undefined without calling when callee is nullish.

Fields

§callee: Box<TsExpr>
§args: Vec<TsExpr>
§

Function

A function expression with a statement body (1A.35a part B), the form that can be a generator: async function* (params) { body }. An arrow cannot yield, so the Stream generators need this. It prints as an operand bracketed, so an immediately invoked one reads (function () { … })().

Fields

§is_async: bool
§is_generator: bool
§params: Vec<TsParam>
§return_type: Option<TsType>
§body: Vec<TsStmt>
§

Yield(Box<TsExpr>)

yield <expr> (1A.35a part B), legal in a generator TsExpr::Function’s body. It binds looser than any operator, so it is bracketed as an operand.

Implementations§

Source§

impl TsExpr

Source

pub fn raw_using(text: impl Into<String>, names: Vec<String>) -> Self

TsExpr::RawUsing: text, with the names it uses declared.

Source

pub fn bigint(n: impl Display) -> Self

A bigint literal: the digits of n (a leading - allowed), printed with the n suffix.

Source

pub fn needs_receiver_brackets(&self) -> bool

Whether this expression must be bracketed to be the object of a member access (<expr>.name, <expr>(..)). The printer brackets a binary, a cast, an arrow, a conditional or an assignment there itself, but not an await, a unary operator or a number literal (Num or Raw), which would read as await f().op() or 1.op(): those are the forms that keep a bracket the caller writes. A Spread is included defensively: it is legal only as an array item, so a receiver is never one today.

Source

pub fn object(entries: Vec<(String, TsExpr)>) -> Self

The ordinary, single-line object literal, Prop-only — every entry is key: value. events_fanout.rs’s own entries (and this crate’s own printer tests) are all this shape; kept taking a plain Vec<(String, TsExpr)> rather than Vec<TsObjectEntry> so none of those existing call sites needed to change when TsObjectEntry was added (#1321) — see TsExpr::object_entries for the mixed-entry form workers.rs itself needs (shorthand/spread/method entries).

Source

pub fn multiline_object(entries: Vec<(String, TsExpr)>) -> Self

One entry per line, each with its own trailing comma — see TsExpr::Object’s own doc for the real shape and the depth-awareness this needs at the print site. Prop-only, the same convenience TsExpr::object’s own doc explains.

Source

pub fn object_entries(entries: Vec<TsObjectEntry>) -> Self

The single-line object literal, taking TsObjectEntry directly — for a mixed entry list (shorthand/spread/method alongside Prop), which TsExpr::object’s own Vec<(String, TsExpr)> convenience can’t represent. #1321’s own real grounding: workers.rs’s local capability-provider deps object mixes shorthand names ({ cap1, cap2 }) with explicit key: value entries (__exec: exec) in one literal.

Source

pub fn multiline_object_entries(entries: Vec<TsObjectEntry>) -> Self

TsExpr::multiline_object’s own TsObjectEntry sibling — #1321’s own real grounding: workers.rs’s compose-returned surface object is one shorthand-async-Method entry per wrapper, one per line.

Source

pub fn multiline_object_ending_at( entries: Vec<TsObjectEntry>, end_span: Span, ) -> Self

TsExpr::multiline_object_entries whose closing } line maps to end_span (1A.32a) — a service object’s closing line belongs to the service, not to its last handler’s final body line.

Source

pub fn multiline_conditional( test: TsExpr, consequent: TsExpr, alternate: TsExpr, ) -> Self

A TsExpr::MultilineConditional: test, then ? consequent and : alternate on their own lines.

Source

pub fn array(items: Vec<TsExpr>) -> Self

The ordinary, single-line array literal — every real site before #1325.

Source

pub fn multiline_array(items: Vec<TsExpr>) -> Self

One entry per line, each with its own trailing comma — see TsExpr::Array’s own doc for the real shape and the depth-awareness this needs at the print site. #1325’s own real grounding: emit_test_main’s own modules array.

Source

pub fn template_lit(parts: Vec<String>, exprs: Vec<TsExpr>) -> Self

A template literal — see TsExpr::TemplateLit’s own doc for the real shape and its no-escaping boundary. The sole caller-facing invariant (parts.len() == exprs.len() + 1) is asserted here rather than left to render_expr’s own parts-driven loop, which would otherwise silently drop trailing exprs on a malformed tree instead of failing loudly (review of #1326, finding 1).

Trait Implementations§

Source§

impl Clone for TsExpr

Source§

fn clone(&self) -> TsExpr

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for TsExpr

Source§

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

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

impl PartialEq for TsExpr

Source§

fn eq(&self, other: &TsExpr) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for TsExpr

Auto Trait Implementations§

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.

§

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

§

fn fg(&self, value: Color) -> Painted<&T>

Returns a styled value derived from self with the foreground set to value.

This method should be used rarely. Instead, prefer to use color-specific builder methods like red() and green(), which have the same functionality but are pithier.

§Example

Set foreground color to white using fg():

use yansi::{Paint, Color};

painted.fg(Color::White);

Set foreground color to white using white().

use yansi::Paint;

painted.white();
§

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

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

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

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

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

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

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));
§

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

fn bg(&self, value: Color) -> Painted<&T>

Returns a styled value derived from self with the background set to value.

This method should be used rarely. Instead, prefer to use color-specific builder methods like on_red() and on_green(), which have the same functionality but are pithier.

§Example

Set background color to red using fg():

use yansi::{Paint, Color};

painted.bg(Color::Red);

Set background color to red using on_red().

use yansi::Paint;

painted.on_red();
§

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

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

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

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

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

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

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));
§

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

fn attr(&self, value: Attribute) -> Painted<&T>

Enables the styling [Attribute] value.

This method should be used rarely. Instead, prefer to use attribute-specific builder methods like bold() and underline(), which have the same functionality but are pithier.

§Example

Make text bold using attr():

use yansi::{Paint, Attribute};

painted.attr(Attribute::Bold);

Make text bold using using bold().

use yansi::Paint;

painted.bold();
§

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

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

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

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

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

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

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

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

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

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());
§

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

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

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

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

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

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

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

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

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

fn quirk(&self, value: Quirk) -> Painted<&T>

Enables the yansi [Quirk] value.

This method should be used rarely. Instead, prefer to use quirk-specific builder methods like mask() and wrap(), which have the same functionality but are pithier.

§Example

Enable wrapping using .quirk():

use yansi::{Paint, Quirk};

painted.quirk(Quirk::Wrap);

Enable wrapping using wrap().

use yansi::Paint;

painted.wrap();
§

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

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

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

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

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

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

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

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

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

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());
§

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

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

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

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

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

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

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

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

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

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);
§

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

Create a new [Painted] with a default [Style]. Read more
§

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.