An Elixir library for defining structs with a type without writing boilerplate code.
TypedStruct is an Elixir library that provides a domain-specific language (DSL) for defining structs along with their types, enforced keys, and default values in a single, concise block. It solves the problem of writing repetitive, error-prone boilerplate code when creating typed structs in Elixir, automatically generating the necessary `defstruct`, `@enforce_keys`, and `@type t()` definitions.
Elixir developers who frequently define structs with associated types and want to reduce boilerplate, ensure consistency, and minimize errors in their codebase.
Developers choose TypedStruct because it dramatically reduces manual coding, enforces correctness by synchronizing struct and type definitions, and offers extensibility through a plugin system, making it a robust tool for maintaining typed structs in Elixir projects.
An Elixir library for defining structs with a type without writing boilerplate code.
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
The typedstruct block and field macro eliminate repetitive code, allowing structs, types, enforced keys, and defaults to be defined in one place, as shown in the README's comparison of manual vs. TypedStruct definitions.
It intelligently generates the t() type, handling nullable types based on enforce and default options, reducing manual errors and ensuring consistency between struct and type definitions.
Supports global enforce defaults, opaque types for encapsulation, and submodule creation via the module option, catering to various use cases without extra boilerplate.
The plugin interface allows integration with libraries like Lens for lens generation, and the README lists available plugins, though the ecosystem is still growing.
Type definitions are generated at compile time with no built-in runtime validation; errors like incorrect field types may only surface during compilation, not in production.
The plugin ecosystem is small, with only a few core plugins available, and key ideas like default value type-checking are noted as unimplemented in the README's roadmap.
For projects with very few structs or no need for types, the DSL adds dependency and complexity where plain defstruct might suffice, as admitted in the philosophy targeting 'lazy developers'.