pub trait Flow {
type WithoutGenerics: Flow + ?Sized;
type OptionInnerType: ?Sized;
const IS_ENUM: bool = false;
Show 14 methods
// Required methods
fn name(cfg: &Config) -> String;
fn inline(cfg: &Config) -> String;
// Provided methods
fn docs() -> Option<String> { ... }
fn ident(cfg: &Config) -> String { ... }
fn decl(cfg: &Config) -> String { ... }
fn decl_concrete(cfg: &Config) -> String { ... }
fn inline_flattened(cfg: &Config) -> String { ... }
fn visit_dependencies(_: &mut impl TypeVisitor)
where Self: 'static { ... }
fn visit_generics(_: &mut impl TypeVisitor)
where Self: 'static { ... }
fn dependencies(cfg: &Config) -> Vec<Dependency>
where Self: 'static { ... }
fn output_path() -> Option<PathBuf> { ... }
fn export(cfg: &Config) -> Result<(), ExportError>
where Self: 'static { ... }
fn export_all(cfg: &Config) -> Result<(), ExportError>
where Self: 'static { ... }
fn export_to_string(cfg: &Config) -> Result<String, ExportError>
where Self: 'static { ... }
}Expand description
The core trait. Derive it on your types to generate Flow declarations.
Mirrors the ts-rs TS trait interface.
Provided Associated Constants§
Required Associated Types§
Sourcetype WithoutGenerics: Flow + ?Sized
type WithoutGenerics: Flow + ?Sized
If this type does not have generic parameters, then WithoutGenerics should be Self.
If the type does have generic parameters, then all generic parameters must be replaced
with a dummy type, e.g flowjs_rs::Dummy or ().
The only requirement for these dummy types is that output_path() must return None.
Sourcetype OptionInnerType: ?Sized
type OptionInnerType: ?Sized
If the implementing type is std::option::Option<T>, then this associated type is set
to T. All other implementations of Flow should set this type to Self instead.
Required Methods§
Provided Methods§
Sourcefn docs() -> Option<String>
fn docs() -> Option<String>
JSDoc/Flow comment to describe this type – when Flow is derived, docs are
automatically read from your doc comments or #[doc = ".."] attributes.
Sourcefn decl(cfg: &Config) -> String
fn decl(cfg: &Config) -> String
Declaration of this type, e.g. type User = {| +user_id: number |};.
This function will panic if the type has no declaration.
If this type is generic, then all provided generic parameters will be swapped for placeholders, resulting in a generic Flow definition.
Sourcefn decl_concrete(cfg: &Config) -> String
fn decl_concrete(cfg: &Config) -> String
Declaration of this type using the supplied generic arguments.
The resulting Flow definition will not be generic. For that, see Flow::decl().
If this type is not generic, then this function is equivalent to Flow::decl().
Sourcefn inline_flattened(cfg: &Config) -> String
fn inline_flattened(cfg: &Config) -> String
Flatten a type declaration. This function will panic if the type cannot be flattened.
Sourcefn visit_dependencies(_: &mut impl TypeVisitor)where
Self: 'static,
fn visit_dependencies(_: &mut impl TypeVisitor)where
Self: 'static,
Iterate over all dependencies of this type.
Sourcefn visit_generics(_: &mut impl TypeVisitor)where
Self: 'static,
fn visit_generics(_: &mut impl TypeVisitor)where
Self: 'static,
Iterate over all type parameters of this type.
Sourcefn dependencies(cfg: &Config) -> Vec<Dependency>where
Self: 'static,
fn dependencies(cfg: &Config) -> Vec<Dependency>where
Self: 'static,
Resolve all dependencies of this type recursively.
Sourcefn output_path() -> Option<PathBuf>
fn output_path() -> Option<PathBuf>
Output file path relative to the export directory.
Sourcefn export(cfg: &Config) -> Result<(), ExportError>where
Self: 'static,
fn export(cfg: &Config) -> Result<(), ExportError>where
Self: 'static,
Export this type to disk.
Sourcefn export_all(cfg: &Config) -> Result<(), ExportError>where
Self: 'static,
fn export_all(cfg: &Config) -> Result<(), ExportError>where
Self: 'static,
Export this type to disk, together with all of its dependencies.
Sourcefn export_to_string(cfg: &Config) -> Result<String, ExportError>where
Self: 'static,
fn export_to_string(cfg: &Config) -> Result<String, ExportError>where
Self: 'static,
Render this type as a string, returning the full file content.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.