Skip to main content

Config

Struct Config 

Source
pub struct Config { /* private fields */ }
Expand description

Configuration that affects the generation of TypeScript bindings and how they are exported.

Implementations§

Source§

impl Config

Source

pub fn new() -> Self

Creates a new Config with default values.

Source

pub fn from_env() -> Self

Creates a new Config with values read from environment variables.

VariableDescriptionDefault
TS_RS_EXPORT_DIRBase directory into which bindings will be exported./bindings
TS_RS_IMPORT_EXTENSIONFile extension used in import statementsnone
TS_RS_LARGE_INTBinding used for large integer types (i64, u64, i128, u128)bigint
Source

pub fn with_large_int(self, ty: impl Into<String>) -> Self

Sets the TypeScript type used to represent large integers. Here, “large” refers to integers that can not be losslessly stored using the 64-bit “binary64” IEEE 754 float format used by JavaScript.
Those include u64, i64, u128, and i128`.

Default: "bigint"

Source

pub fn large_int(&self) -> &str

Returns the TypeScript type used to represent large integers.

Source

pub fn with_v11_hashmap(self) -> Self

👎Deprecated: this option is merely meant to aid migration to v12 and will be removed in a future release

When enabled, HashMap<K, V> and similar types will always be translated to { [key in K]?: V }.
Normally, with this option disabled, { [key in K]: V } is generated instead, unless the key K is an enum.
This option is only intended to aid migration and will be removed in a future release.

Default: disabled

Source

pub fn with_out_dir(self, dir: impl Into<PathBuf>) -> Self

Sets the output directory into which bindings will be exported.
This affects TS::export, TS::export_all, and the automatic export of types annotated with #[ts(export)] when cargo test is run.

Default: ./bindings

Source

pub fn out_dir(&self) -> &Path

Returns the output directory into which bindings will be exported.

Source

pub fn with_import_extension(self, ext: Option<impl Into<String>>) -> Self

Sets the file extension used for import statements in generated TypeScript files.

Default: None

Source

pub fn import_extension(&self) -> Option<&str>

Returns the file extension used for import statements in generated TypeScript files.

Source

pub fn with_array_tuple_limit(self, limit: usize) -> Self

Sets the maximum size of arrays ([T; N]) up to which they are treated as TypeScript tuples ([T, T, ...]).
Arrays beyond this size will instead result in a TypeScript array (Array<T>).

Default: 64

Source

pub fn array_tuple_limit(&self) -> usize

Returns the maximum size of arrays ([T; N]) up to which they are treated as TypeScript tuples ([T, T, ...]).

Trait Implementations§

Source§

impl Default for Config

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Freeze for Config

§

impl RefUnwindSafe for Config

§

impl Send for Config

§

impl Sync for Config

§

impl Unpin for Config

§

impl UnwindSafe for Config

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> 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.

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.