You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Define your structs and types in one place. TypedStructor generates `defstruct`, type specs, and `@enforce_keys` while keeping your code clean and explicit.
8
+
TypedStructor eliminates the boilerplate of defining Elixir structs, type specs, and enforced keys separately. Define them once, keep them in sync automatically.
9
9
10
-
## Why TypedStructor?
11
-
12
-
**Without TypedStructor**, you write everything twice:
10
+
**Before** -- three declarations that must stay in sync manually:
13
11
14
12
```elixir
15
13
defmoduleUserdo
@@ -24,7 +22,7 @@ defmodule User do
24
22
end
25
23
```
26
24
27
-
**With TypedStructor**, you write it once:
25
+
**After** -- a single source of truth:
28
26
29
27
```elixir
30
28
defmoduleUserdo
@@ -38,7 +36,16 @@ defmodule User do
38
36
end
39
37
```
40
38
41
-
Same result, half the boilerplate. Your struct definition and type spec stay in sync automatically.
39
+
## Feature Highlights
40
+
41
+
-**Single definition** -- struct, type spec, and `@enforce_keys` generated from one block
42
+
-**Nullable by default** -- unenforced fields without defaults automatically include `| nil`
43
+
-**Fine-grained null control** -- override nullability per-field or per-block with the `:null` option
44
+
-**Opaque and custom types** -- generate `@opaque`, `@typep`, or rename the type from `t()`
> Check out the [Plugin Guides](guides/plugins/introduction.md) to learn how to create your own plugins.
312
-
> All examples include copy-paste-ready code.
313
-
314
-
## Documentation
315
-
316
-
Add `@moduledoc` at the module level, and `@typedoc` inside the block:
317
-
318
-
```elixir
319
-
defmoduleUserdo
320
-
@moduledoc "User management structures"
321
-
useTypedStructor
247
+
typed_structor define_struct:falsedo
248
+
field :email, String.t(), enforce:true
322
249
323
-
typed_structor do
324
-
@typedoc "A user with authentication details"
250
+
useEcto.Schema
251
+
@primary_keyfalse
325
252
326
-
field :id, pos_integer()
327
-
field :name, String.t()
253
+
schema "users"do
254
+
Ecto.Schema.field(:email, :string)
255
+
end
328
256
end
329
257
end
330
258
```
331
259
332
-
<!-- MODULEDOC -->
260
+
This generates only the type spec while letting the other library handle the struct definition.
261
+
262
+
For full Ecto integration with typed fields, see [EctoTypedSchema](https://github.com/elixir-typed-structor/ecto_typed_schema) -- a companion library built on TypedStructor.
333
263
334
264
## Learn More
335
265
336
-
-**API Reference**: Check `TypedStructor.typed_structor/2` and `TypedStructor.field/3` for all options
337
-
-**Plugin System**: See `TypedStructor.Plugin` for creating custom plugins
338
-
-**Guides**: Visit [hexdocs.pm/typed_structor](https://hexdocs.pm/typed_structor) for detailed guides
266
+
-[HexDocs](https://hexdocs.pm/typed_structor) -- full API reference and guides
267
+
-[Plugin Guides](https://hexdocs.pm/typed_structor/introduction.html) -- build and use plugins
268
+
-[Changelog](https://hexdocs.pm/typed_structor/changelog.html) -- release history
0 commit comments