index
@ts-rust/std / Types
Types
The Types
module defines common utility types used throughout
the @ts-rust/std
package. It exports foundational types such as Primitive
,
Cloneable
, Clone
, Recoverable
, and MaybePromise
, which provide building
blocks for type-safe programming in TypeScript. Inspired by Rust's type system,
these types enable better handling of cloning, error recovery, and
synchronous/asynchronous value interoperability. Use this module to leverage
these utility types in your TypeScript applications for more robust and
predictable code.
Interfaces
Interface | Description |
---|---|
Defines a type The Clone interface ensures that any type implementing it can produce
a duplicate of its current instance via the Similar to Rust's
Example
| |
Defines a type The Recoverable interface ensures that any type implementing it can handle
errors gracefully through the Similar to JavaScript's Promise error handling pattern, this interface standardizes error recovery across different implementation types. It allows consuming code to safely handle both the successful and error paths without needing to know the specific error handling mechanisms of the underlying implementation. The Example
|
Type Aliases
Type Alias | Description |
---|---|
Defines a type The Cloneable type encompasses all values that can be cloned into a new, independent instance. It is a union of:
Inspired by Rust's distinction between
This type is broader than Clone alone, as it includes both implicitly
copyable primitives and explicitly cloneable types. For
non-primitive types, the Example
| |
Represents either a value of type The MaybePromise type provides flexibility when working with both synchronous and asynchronous values in a unified way. It allows functions and interfaces to accept either immediate values or promises without needing separate implementations, simplifying API design and improving interoperability between synchronous and asynchronous code. The | |
Represents all JavaScript primitive types. A primitive is any value that is not an object and has no methods.
Primitives are immutable (except for The
Objects, arrays, functions, and other reference types are not primitives. Use this type to enforce that a value belongs to one of these fundamental types. |