Skip to main content

TsStmt

Struct TsStmt 

Source
pub struct TsStmt {
    pub span: Option<Span>,
    pub nested_map: Option<SourceMapBuilder>,
    /* private fields */
}
Expand description

One statement — a Verbatim-tagged escape hatch (still constructible only via TsStmt::verbatim, per #1307’s Decision D — the verbatim_sites probe needs exactly one string to line-scan for), or, from this slice, a real structured kind. The real kinds have no such sealing: they’re normal typed constructors, not a “wrap opaque text” escape hatch, so the verbatim_sites concern that motivates verbatim’s own single-constructor discipline doesn’t apply to them.

Fields§

§span: Option<Span>

Where this statement’s content originated in the .bynk source, if known. Only a top-level statement’s own span is currently recorded as a source-map checkpoint (crate::printer::print, unchanged from P7.5/R7.4’s own scope) — a nested statement (inside a Block, If, ForOf, TryCatch) still carries this field structurally, for whichever future slice gives sub-statement source maps real value, but the printer does not yet record a checkpoint from it. Named here explicitly (P7.8’s own accepted proposal: “an implementation-time call within this same shape”) rather than left ambiguous.

§nested_map: Option<SourceMapBuilder>

#1477’s own real gap: a body-bearing statement — in practice always a TsStmtKind::Raw/TsStmtKind::Verbatim opaque blob standing in for a lowered function/method body (ADR 0391’s own permanent exclusion) — carries its own per-statement source-map checkpoints, collected by the caller’s own body-local SourceMapBuilder before this node existed. Before this field, every real bynk-emit caller that needed to merge those checkpoints into its own module map had to reverse-engineer this node’s own print-time byte offset from the outsidebynk-emit’s own emit_class_method_and_merge_source_map (emitter/emit.rs) recovers it by subtracting known lengths and string-matching the printed text’s own tail, degrading to a silent skip if that search fails; still live for emit_service/emit_agent’s own not-yet-converted call sites (#1481/#1482). emit_free_fn used to recover it by separate, independent exact arithmetic, guarded by a debug_assert! — #1480 converted it to set this field directly instead, the first real bynk-emit caller to do so. Both existed only because nothing reported this node’s own real print-time offset directly. Setting this field lets the printer itself do the merge, at the exact offset it is about to write this node’s text to — no reverse-engineering, no silent-skip fallback (see this crate’s own private printer::render_block_stmts for the handling). None for every real site that predates this field and every node whose own text carries no nested checkpoints of its own — the overwhelmingly common case, and the reason this is an Option, not a required field.

Implementations§

Source§

impl TsStmt

Source

pub fn verbatim( origin: VerbatimOrigin, text: impl Into<String>, span: Option<Span>, ) -> Self

The one constructor for a Verbatim-kinded statement.

Source

pub fn decl(decl: TsDecl, span: Option<Span>) -> Self

Source

pub fn const_stmt( name: TsBindingName, ty: Option<TsType>, init: TsExpr, span: Option<Span>, ) -> Self

Source

pub fn let_stmt( name: TsBindingName, ty: Option<TsType>, init: Option<TsExpr>, span: Option<Span>, ) -> Self

Source

pub fn expr_stmt(expr: TsExpr, span: Option<Span>) -> Self

Source

pub fn return_stmt(expr: Option<TsExpr>, span: Option<Span>) -> Self

Source

pub fn throw_stmt(expr: TsExpr, span: Option<Span>) -> Self

Source

pub fn if_stmt(cond: TsExpr, then_branch: TsStmt, span: Option<Span>) -> Self

Source

pub fn if_else_stmt( cond: TsExpr, then_branch: TsStmt, else_branch: TsStmt, span: Option<Span>, ) -> Self

Source

pub fn if_else_same_line_stmt( cond: TsExpr, then_branch: TsStmt, else_branch: TsStmt, span: Option<Span>, ) -> Self

TsStmt::if_else_stmt’s own sibling with } else { on one line — #1325’s own real gap, emit_test_main’s own real else spacing. See TsStmtKind::If’s own doc for why this needs to be a distinct constructor rather than a change to the existing default.

Source

pub fn for_of( binding: impl Into<String>, iter: TsExpr, body: TsStmt, span: Option<Span>, ) -> Self

Source

pub fn for_stmt( name: impl Into<String>, init: TsExpr, test: TsExpr, body: TsStmt, span: Option<Span>, ) -> Self

for (let <name> = <init>; <test>; <update>++) <body> — see TsStmtKind::For’s own doc for exactly what this construct does and does not represent.

Source

pub fn try_catch( try_block: TsStmt, catch_param: Option<impl Into<String>>, catch_block: TsStmt, span: Option<Span>, ) -> Self

Source

pub fn block(stmts: Vec<TsStmt>, span: Option<Span>) -> Self

Source

pub fn continue_stmt(span: Option<Span>) -> Self

Source

pub fn assign(target: TsExpr, value: TsExpr, span: Option<Span>) -> Self

Source

pub fn comment(text: impl Into<String>, span: Option<Span>) -> Self

Source

pub fn doc_comment(text: impl Into<String>, span: Option<Span>) -> Self

Source

pub fn blank(span: Option<Span>) -> Self

Source

pub fn switch_stmt( discriminant: TsExpr, cases: Vec<TsSwitchCase>, span: Option<Span>, ) -> Self

Source

pub fn inline_block(stmts: Vec<TsStmt>, span: Option<Span>) -> Self

Source

pub fn increment(expr: TsExpr, span: Option<Span>) -> Self

Source

pub fn raw(text: impl Into<String>, span: Option<Span>) -> Self

The one constructor for a Raw-kinded statement — text is printed verbatim, exactly as given (see TsStmtKind::Raw’s own doc for why this is a distinct kind from Verbatim, not a reuse of it).

Trait Implementations§

Source§

impl Clone for TsStmt

Source§

fn clone(&self) -> TsStmt

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 TsStmt

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.