#[non_exhaustive]pub struct Exporter {
pub header: Cow<'static, str>,
pub bigint: BigIntExportBehavior,
pub layout: Layout,
pub serde: Option<SerdeMode>,
/* private fields */
}Expand description
Typescript language exporter.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.header: Cow<'static, str>Custom header prepended to exported files.
bigint: BigIntExportBehaviorStrategy for exporting Rust bigint-compatible primitives.
layout: LayoutOutput layout mode for generated TypeScript.
serde: Option<SerdeMode>Optional Serde compatibility processing mode.
Implementations§
Source§impl Exporter
impl Exporter
Sourcepub fn framework_prelude(self, prelude: impl Into<Cow<'static, str>>) -> Self
pub fn framework_prelude(self, prelude: impl Into<Cow<'static, str>>) -> Self
Provide a prelude which is added to the start of all exported files.
Sourcepub fn framework_runtime(
self,
builder: impl Fn(FrameworkExporter<'_>) -> Result<Cow<'static, str>, Error> + Send + Sync + 'static,
) -> Self
pub fn framework_runtime( self, builder: impl Fn(FrameworkExporter<'_>) -> Result<Cow<'static, str>, Error> + Send + Sync + 'static, ) -> Self
Add some custom Typescript or Javascript code that is exported as part of the bindings.
It’s appending to the types file for single-file layouts or put in a root index.{ts/js} for multi-file.
The closure is wrapped in [specta::datatype::collect()] to capture any referenced types.
Ensure you call T::reference() within the closure if you want an import to be created.
Sourcepub fn branded_type_impl(
self,
builder: impl for<'a> Fn(BrandedTypeExporter<'a>, &Branded) -> Result<Cow<'static, str>, Error> + Send + Sync + 'static,
) -> Self
pub fn branded_type_impl( self, builder: impl for<'a> Fn(BrandedTypeExporter<'a>, &Branded) -> Result<Cow<'static, str>, Error> + Send + Sync + 'static, ) -> Self
Configure how specta_typescript::branded! types are rendered with exporter context.
This callback receives both the branded payload and a BrandedTypeExporter, allowing
you to call BrandedTypeExporter::inline / BrandedTypeExporter::reference while
preserving the current export configuration.
§Examples
ts-brand style:
let exporter = Typescript::default().branded_type_impl(|ctx, branded| {
let datatype = ctx.inline(branded.ty())?;
Ok(Cow::Owned(format!(
"import(\"ts-brand\").Brand<{}, \"{}\">",
datatype,
branded.brand()
)))
});Effect style:
let exporter = Typescript::default().branded_type_impl(|ctx, branded| {
let datatype = ctx.inline(branded.ty())?;
Ok(Cow::Owned(format!(
"{} & import(\"effect\").Brand.Brand<\"{}\">",
datatype,
branded.brand()
)))
});Sourcepub fn header(self, header: impl Into<Cow<'static, str>>) -> Self
pub fn header(self, header: impl Into<Cow<'static, str>>) -> Self
Configure a header for the file.
This is perfect for configuring lint ignore rules or other file-level comments.
Sourcepub fn bigint(self, bigint: BigIntExportBehavior) -> Self
pub fn bigint(self, bigint: BigIntExportBehavior) -> Self
Configure the BigInt handling behaviour
Sourcepub fn with_serde(self, mode: SerdeMode) -> Self
pub fn with_serde(self, mode: SerdeMode) -> Self
Configure the exporter to use specta-serde with the specified mode
Sourcepub fn with_serde_serialize(self) -> Self
pub fn with_serde_serialize(self) -> Self
Configure the exporter to export the types for #[derive(serde::Serialize)]
Sourcepub fn with_serde_deserialize(self) -> Self
pub fn with_serde_deserialize(self) -> Self
Configure the exporter to export the types for #[derive(serde::Deserialize)]