Skip to main content

TsType

Enum TsType 

Source
pub enum TsType {
    Named {
        name: String,
        type_args: Vec<TsType>,
    },
    Array {
        element: Box<TsType>,
        readonly: bool,
    },
    Object(Vec<TsTypeMember>),
    Fn {
        params: Vec<TsType>,
        ret: Box<TsType>,
    },
    Union {
        members: Vec<TsType>,
        multiline: bool,
    },
    Intersection(Vec<TsType>),
}
Expand description

A type-position node. Named (extended with type arguments — a real gap the reference sketch left unaddressed: Record<string, Array<{...}>>/Promise<Response> both need one, and a bare Named with no type-argument slot cannot represent either), Array (extended with a readonly modifier — P7.9’s own real gap: every List/Query element type bynk-emit’s ts_type_ref*/ts_ty families build is readonly T[], not plain T[]), Object, and Fn (P7.9’s own second real gap — the query-thunk wrapper (() => readonly T[]) and a real parametered function type (a0: T0, …) => Ret both need one) — not the sketch’s Union/Intersection/Literal/TypeParam/Readonly (still unused; readonly here is a modifier on Array, not the sketch’s own separate Readonly wrapper variant).

Variants§

§

Named

A named type, optionally generic — string/unknown (no type arguments) or Record<string, T>/Promise<Response> (some).

Fields

§name: String
§type_args: Vec<TsType>
§

Array

T[] (readonly: false) or readonly T[] (readonly: true) — TypeScript’s own postfix array-type syntax (not the equivalent Array<T>/ReadonlyArray<T> generic spelling either family uses).

Hazard (review of #1315/#1316, not yet closed): the printer does not parenthesise element when it is itself a TsType::Union or TsType::FnArray { element: Union(..), .. } prints as A | B[], which TypeScript reads as A | (B[]), not the intended (A | B)[]; likewise a Fn element’s own [] binds to its return type, not the whole function type. Not a P7.9 regression — every bynk-emit call site building this exact malformed shape (Ty::List of an Ty::ActorSum) produced the identical bytes before this slice too, so the zero-diff bar is genuinely met. Fixing it is a real output change, out of this slice’s own behaviour- preserving scope — a caller building Array over Union/Fn today must not trust the printer to parenthesise correctly.

Fields

§element: Box<TsType>
§readonly: bool
§

Object(Vec<TsTypeMember>)

A type-position object shape, e.g. { type: string; payload: unknown } — semicolon-separated, always printed on one line (see TsExpr::Object’s own doc for the value-position contrast). An interface’s own members are each printed on their own line by TsDecl::Interface’s printer, independent of this variant’s own (always-inline) rendering — the two only look different because TsDecl::Interface is the thing choosing to put each member on its own line, not because Object has two rendering modes.

#1323 replaced the plain Vec<(String, TsType, bool)> (optional only, #1321) with TsTypeMemberworkers_entry.rs’s own real gap needed both a readonly modifier (every structural type this file builds is readonly-qualified, e.g. { readonly cron: string; readonly scheduledTime: number }) and a method-signature member (ack(): void, retry(): void, waitUntil(promise: Promise< unknown>): void), neither representable by one more anonymous tuple bool — a fourth positional bool next to optional would be genuinely ambiguous at call sites (readonly vs. optional, ordered how?), the same reasoning TsObjectEntry already used over a raw tuple for the value-position sibling.

§

Fn

(a0: T0, a1: T1, …) => Ret — a function type. Parameters carry no name of their own (just their type); the printer numbers them positionally (a0, a1, …), matching the exact convention bynk-emit’s own pre-P7.9 ts_type_ref_with/ts_ty already used (TypeScript requires some name in function-type syntax, and nothing about a TypeRef::Fn/Ty::Fn parameter carries a real one to use instead). A zero-params Fn is the query-thunk wrapper shape, () => Ret. See TsType::Array’s own doc for a real, unclosed parenthesisation hazard when a Fn sits inside one.

Fields

§params: Vec<TsType>
§

Union

A | B | C — a type-position union. Added in review of #1315: bynk-emit’s ts_ty builds a real union type for a resolved multi-actor sum (Ty::ActorSum, discriminated-union members tagged by actor name), a shape none of Named/Array/Object/Fn can represent — a real, grounded gap the same way readonly/Fn themselves were (P7.9’s own accepted proposal), not a speculative addition. Each member prints through the ordinary render_type recursion; a member that is itself a Union is legal to construct but nothing in bynk-emit builds one today. See TsType::Array’s own doc for a real, unclosed parenthesisation hazard when a Union sits inside one.

multiline (#1339): false (via TsType::union) is this variant’s original single-line A | B | C form, unchanged. true (via TsType::multiline_union) is emit_sum_type’s own real discriminated-union shape — one variant per line, a leading | on every line except the first (which gets equivalent spacing instead), the closing ; appended directly to the last variant’s own line. Mirrors TsExpr::Object’s own multiline field precedent (#1317), but — unlike that one — needs no depth-aware wrapper: the pre-conversion writeln! code this reproduces always used a fixed two-space indent regardless of nesting (this shape is only ever a top-level export type alias body, never nested inside another type), so render_type stays entirely depth-unaware here too. Only rendered correctly from TsDecl::TypeAlias’s own top-level render — not reachable, and not given a defined rendering, from any nested position (an array element, a type argument, …), the same named boundary TsExpr::Object’s own multiline doc already draws for its own nested case.

Fields

§members: Vec<TsType>
§multiline: bool
§

Intersection(Vec<TsType>)

A & B — a type-position intersection. #1339’s own real gap: emit_refined_type’s own branded-type alias, {base} & { readonly __brand: "..." }, has no representation among Named/Array/Object/Fn/Union — mirrors Union’s own shape/precedent exactly (a flat Vec, each member printed through the ordinary render_type recursion, joined by &), single-line only (nothing in bynk-emit builds a multi-line intersection).

Implementations§

Source§

impl TsType

Source

pub fn named(name: impl Into<String>) -> Self

A plain named type with no type arguments — string, unknown, Request, …

Source

pub fn named_with_args(name: impl Into<String>, type_args: Vec<TsType>) -> Self

A generic named type — Record<K, V>, Promise<T>, …

Source

pub fn array(element: TsType) -> Self

T[] — the non-readonly array shape.

Source

pub fn readonly_array(element: TsType) -> Self

readonly T[].

Source

pub fn union(members: Vec<TsType>) -> Self

A | B | C — the original single-line union form, unchanged.

Source

pub fn multiline_union(members: Vec<TsType>) -> Self

emit_sum_type’s own real multi-line discriminated-union shape — see TsType::Union’s own doc for the exact rendering rules and why this needs no depth parameter.

Source

pub fn intersection(members: Vec<TsType>) -> Self

A & B — an intersection type.

Trait Implementations§

Source§

impl Clone for TsType

Source§

fn clone(&self) -> TsType

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 TsType

Source§

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

Formats the value using the given formatter. Read more

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.