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
outside — bynk-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
impl TsStmt
Sourcepub fn verbatim(
origin: VerbatimOrigin,
text: impl Into<String>,
span: Option<Span>,
) -> Self
pub fn verbatim( origin: VerbatimOrigin, text: impl Into<String>, span: Option<Span>, ) -> Self
The one constructor for a Verbatim-kinded statement.
pub fn decl(decl: TsDecl, span: Option<Span>) -> Self
pub fn const_stmt( name: TsBindingName, ty: Option<TsType>, init: TsExpr, span: Option<Span>, ) -> Self
pub fn let_stmt( name: TsBindingName, ty: Option<TsType>, init: Option<TsExpr>, span: Option<Span>, ) -> Self
pub fn expr_stmt(expr: TsExpr, span: Option<Span>) -> Self
pub fn return_stmt(expr: Option<TsExpr>, span: Option<Span>) -> Self
pub fn throw_stmt(expr: TsExpr, span: Option<Span>) -> Self
pub fn if_stmt(cond: TsExpr, then_branch: TsStmt, span: Option<Span>) -> Self
pub fn if_else_stmt( cond: TsExpr, then_branch: TsStmt, else_branch: TsStmt, span: Option<Span>, ) -> Self
Sourcepub fn if_else_same_line_stmt(
cond: TsExpr,
then_branch: TsStmt,
else_branch: TsStmt,
span: Option<Span>,
) -> Self
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.
pub fn for_of( binding: impl Into<String>, iter: TsExpr, body: TsStmt, span: Option<Span>, ) -> Self
Sourcepub fn for_stmt(
name: impl Into<String>,
init: TsExpr,
test: TsExpr,
body: TsStmt,
span: Option<Span>,
) -> Self
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.
pub fn try_catch( try_block: TsStmt, catch_param: Option<impl Into<String>>, catch_block: TsStmt, span: Option<Span>, ) -> Self
pub fn block(stmts: Vec<TsStmt>, span: Option<Span>) -> Self
pub fn continue_stmt(span: Option<Span>) -> Self
pub fn assign(target: TsExpr, value: TsExpr, span: Option<Span>) -> Self
pub fn comment(text: impl Into<String>, span: Option<Span>) -> Self
pub fn doc_comment(text: impl Into<String>, span: Option<Span>) -> Self
pub fn blank(span: Option<Span>) -> Self
pub fn switch_stmt( discriminant: TsExpr, cases: Vec<TsSwitchCase>, span: Option<Span>, ) -> Self
pub fn inline_block(stmts: Vec<TsStmt>, span: Option<Span>) -> Self
pub fn increment(expr: TsExpr, span: Option<Span>) -> Self
Trait Implementations§
Auto Trait Implementations§
impl Freeze for TsStmt
impl RefUnwindSafe for TsStmt
impl Send for TsStmt
impl Sync for TsStmt
impl Unpin for TsStmt
impl UnsafeUnpin for TsStmt
impl UnwindSafe for TsStmt
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
§fn fg(&self, value: Color) -> Painted<&T>
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 bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
§fn bg(&self, value: Color) -> Painted<&T>
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>
fn on_primary(&self) -> Painted<&T>
§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
§fn attr(&self, value: Attribute) -> Painted<&T>
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 rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
§fn quirk(&self, value: Quirk) -> Painted<&T>
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 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.
fn clear(&self) -> Painted<&T>
resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.§fn whenever(&self, value: Condition) -> Painted<&T>
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);