Skip to main content

TsDecl

Enum TsDecl 

Source
pub enum TsDecl {
Show 13 variants Import { type_only: bool, names: Vec<String>, from: String, }, ImportNamespace { type_only: bool, alias: String, from: String, }, ImportDefault { alias: String, from: String, }, ReExport { names: Vec<String>, from: String, }, ReExportAll { from: String, }, Export(Box<TsDecl>), Interface { name: String, type_params: Vec<String>, members: Vec<TsTypeMember>, }, ConstDecl { name: String, ty: Option<TsType>, init: TsExpr, }, Class { name: String, fields: Vec<TsClassField>, constructor: Option<TsClassCtor>, methods: Vec<TsClassMethod>, }, Function { name: String, generics: Vec<String>, params: Vec<TsParam>, return_type: Option<TsType>, body: Vec<TsStmt>, is_async: bool, inline: bool, }, TypeAlias { name: String, type_params: Vec<String>, ty: TsType, }, ExportDefault(TsExpr), DeclareConst { name: String, ty: TsType, },
}
Expand description

A top-level declaration. Import, Export, Interface, ConstDecl, and Class were events_fanout.rs’s own grounding (P7.8’s own note: “not the sketch’s Function/TypeAlias — unused in the grounding file”). #1321 (workers.rs) needed both after all — a real gap the accepted proposal’s own Framing didn’t name (its own “no other gap surfaced” checked TsStmt/TsExpr/TsType shapes, not TsDecl ones): compose.ts’s own export function compose(env: Env, …) { … } is a top-level function declaration, and (when the Worker has agents or publishes events) a type DurableObjectNamespace = { … }; fallback alias sits alongside it. Named explicitly as a deviation from the accepted proposal’s own catalogue, not silently added — both are mechanical, direct TsDecl siblings of ConstDecl/Class already here, the same “small, grounded, same class of gap” this track’s own history repeatedly found and closed (P7.8’s Assign/Continue/ TryCatch, Arc C slice 1’s Comment).

Variants§

§

Import

import { a, b } from "spec"; (type_only: false) or import type { a, b } from "spec"; (type_only: true). Only the named-imports form — events_fanout.rs never uses a default import, so none is represented. names entries are pushed verbatim (printer.rs’s own names.join(", ")), so a renamed import (messagesLocales as __locale_declaredLocales, workers.rs’s own locale-negotiation import) is one opaque String entry, not a structured rename — the same “the field is already a raw-text slot” reasoning that also covers a type-prefixed single specifier ("type KVNamespace") inside an otherwise non-type_only import.

Fields

§type_only: bool
§names: Vec<String>
§from: String
§

ImportNamespace

import * as alias from "spec"; — a namespace import, structurally different from TsDecl::Import’s braced named-imports form (no { }, one bound name for the whole module). #1321’s own real gap: workers.rs’s compose.ts imports handlers.js and each referenced unit’s binding module this way; events_fanout.rs never used one. type_only (Arc C, step (10), #1392) mirrors TsDecl::Import’s own identical field, a parallel gap by omission, not deliberate design — emit_cross_context_namespace_ imports’s own real import type * as ns from "..."; form (a Workers-mode consumed-context import reaching the callee’s types only, #661) had no way to represent the type keyword until now.

Fields

§type_only: bool
§alias: String
§from: String
§

ImportDefault

import name from "spec"; — a default import, structurally different from both TsDecl::Import (braced named-imports form) and TsDecl::ImportNamespace (* as form) — no braces, no * as, one bound local name for the module’s own default export. No type_only form — nothing in the grounding file default-imports a type. Arc C, slice 37 (#1409, tests_emit.rs’s own slice G): a per-participant import worker_{ns} from "../workers/{dir}/ index.js"; (the participant’s own Worker entry module’s default export) is the first real default import anywhere in bynk-emit’s own converted content — every prior import site is either named (TsDecl::Import) or namespace (TsDecl::ImportNamespace).

Fields

§alias: String
§from: String
§

ReExport

export { a, b } from "spec"; — a re-export, structurally distinct from both TsDecl::Import (which binds locally, carries no export keyword) and TsDecl::Export (which wraps a whole declaration, not a braced name list re-pointed at another module). #1323’s own real gap: workers_entry.rs re-exports each agent’s Durable Object class from ./handlers.js, and (when the context publishes events) the fan-out DO’s class from ./events_fanout.js. No type_only form — nothing in the grounding file re-exports a type-only name.

Fields

§names: Vec<String>
§from: String
§

ReExportAll

export * from "spec"; — a wildcard re-export, structurally distinct from TsDecl::ReExport (which always carries a braced name list — an empty names there would render the ill-formed export { } from "spec";, not this). Mirrors TsDecl::ImportNamespace’s own “no braces, no name list, one bound target” shape, on the export side. #1329’s own real gap: emit_commons_barrel (bynk-emit/src/project/tests_emit.rs) builds a multi-file commons unit’s barrel module as one export * line per constituent source file.

Fields

§from: String
§

Export(Box<TsDecl>)

Marks the wrapped declaration exported — export class Foo { .. } is Export(Box::new(Class { .. })). A wrapper, not a per-variant exported: bool field, matching the reference sketch’s own naming (TsDecl::Export is a peer variant, not a modifier on each other one).

§

Interface

type_params/per-member readonly (#1339’s own real gap): emit_record_type’s own export interface {name}{params} { readonly {field}: {ty}; ... } — bare generic names (matching ts_type_params’s/TsObjectEntry::Method.generics’s own convention) and a readonly modifier every real field here carries. members reuses TsTypeMember (the exact same shape TsType::Object’s own structural members already use) rather than a bespoke tuple, since readonly is already that type’s own field — this interface’s real content has never needed Method/Index, but nothing about reusing the shared type forecloses a future slice that does.

Fields

§name: String
§type_params: Vec<String>
§

ConstDecl

A top-level const — distinct from TsStmtKind::Const (private — reachable through TsStmt::const_stmt), the local form.

Fields

§name: String
§init: TsExpr
§

Class

Fields

§name: String
§constructor: Option<TsClassCtor>
§

Function

function name(params): ret { body } (is_async: false) or async function name(params): ret { body } (is_async: true) — a top-level function declaration. is_async added by #1325: workers.rs’s own one real site (compose) is never async, so the field didn’t exist until emit_test_main’s own top-level async function main() {...} needed it — the exact “extend narrowly, add it when a future slice’s own grounding needs it” deferral this variant’s own history already named. generics added by #1351: emit_free_fn’s own v0.20a erased generics (export function foo<T>(...)) — bare names only, empty for every non-generic site (compose/main), matching every other real generics-list precedent in this crate (TsObjectEntry::Method.generics #1337, TsExpr::Arrow.generics #1339). inline added by #1369 (Arc C, slice 20, step (9)’s own second sub-slice): emit_agent’s own zero-factory function (function __zeroOf{Name}State(): {Name}State { return {...}; }) is a genuinely single-physical-line declaration — braces and body share the header’s own line, not render_block_stmts’s always-multi-line shape. false (every site landed before #1369) renders the ordinary multi-line body; true reuses render_inline_block’s own compact { stmt; stmt; } shape directly at the declaration’s own header line, the same “one more bool, mirroring an existing precedent” scope TsObjectEntry::Method.inline (#1337) already set for the identical single-line-vs-multi-line tension at a different node kind.

Fields

§name: String
§generics: Vec<String>
§params: Vec<TsParam>
§return_type: Option<TsType>
§body: Vec<TsStmt>
§is_async: bool
§inline: bool
§

TypeAlias

type name = ty; (non-generic) or type name<T, U> = ty; (via type_params, #1339’s own real gap: emit_sum_type’s own generic sum types erase to export type Foo<T> = ...) — a top-level type alias. workers.rs’s own real site: the DurableObjectNamespace local fallback type (emitted only when the Worker has agents or publishes events), never generic — type_params is empty there.

Fields

§name: String
§type_params: Vec<String>
§

ExportDefault(TsExpr)

export default <expr>; — a default export of an expression, not a declaration. #1323’s own real gap (workers_entry.rs’s own top-level shape, export default { fetch, scheduled?, queue? }): TsDecl::Export wraps a TsDecl (a Class/ConstDecl/etc., something with its own name), which cannot represent exporting a bare, unnamed object-literal expression — so this is its own variant, not Export(Box::new(ConstDecl { .. })) with a synthetic name that would print wrong.

§

DeclareConst

declare const name: ty; — an ambient binding with no initialiser, narrowing a global TypeScript otherwise doesn’t know about. #1325’s own real, narrow site: emit_test_main’s own declare const process: { exit(code: number): never; env: { [k: string]: string | undefined } };, narrowing Node’s process global without a @types/node dependency. Distinct from TsDecl::ConstDecl (always has a real init expression) — a declare const has none, by definition; a TsDecl::ConstDecl with a synthetic placeholder init would print wrong (= <something>; where nothing should appear at all).

Fields

§name: String

Trait Implementations§

Source§

impl Clone for TsDecl

Source§

fn clone(&self) -> TsDecl

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 TsDecl

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.