Skip to content

Commit 8296557

Browse files
committed
Add ADT variant codec docs and telemetry dep
Document a new ADT/Variant codec and telemetry support: update README with a Variant codec builder example and add entries to CHANGELOG describing variant codecs and telemetry events. Also add the telemetry dependency (>= 1.0.0 and < 2.0.0) to gleam.toml and manifest.toml (package entry and requirement).
1 parent 55641e8 commit 8296557

4 files changed

Lines changed: 31 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88
notifications for `NodeUp` and `NodeDown`.
99
- `distribute.subscribe(subject)` — Start a monitored subscription.
1010
- `distribute.unsubscribe(monitor_subject)` — Stop a subscription.
11+
- **ADT/Variant Codecs** (`distribute/codec/variant`) — A builder pattern to
12+
easily create codecs for Custom Types (enums) with payload support.
13+
- `variant.new()`, `variant.add()`, `variant.unit()`, `variant.build()`
14+
- **Telemetry** (`distribute/internal/telemetry`) — Erlang `:telemetry` events
15+
for send, receive, encode, decode, registry, and cluster operations.
1116

1217
## v3.0.0 — 2026-02-11
1318

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,35 @@ the fields together!
122122
| `distribute/cluster` | `net_kernel` start/connect/ping |
123123
| `distribute/codec` | Binary codecs for primitives + `subject()` |
124124
| `distribute/codec/composite` | Option, Result, Tuple codecs |
125+
| `distribute/codec/variant` | Build codecs for Custom Types (ADTs) |
125126
| `distribute/codec/tagged` | Tagged messages with version field |
126127
| `distribute/global` | `GlobalSubject(msg)`, `call`, `reply` |
127128
| `distribute/cluster/monitor` | `NodeUp`, `NodeDown` typed events |
128129
| `distribute/registry` | `TypedName(msg)`, `:global` registration |
129130
| `distribute/receiver` | Typed receive, OTP actor wrappers |
130131

132+
### Custom Type Codecs
133+
134+
Seamlessly encode and decode your Algebraic Data Types (enums) with a fluent builder.
135+
136+
```gleam
137+
pub type MyMessage {
138+
Text(String)
139+
Ping
140+
}
141+
142+
import distribute/codec
143+
import distribute/codec/variant
144+
145+
let my_codec =
146+
variant.new()
147+
|> variant.add(0, "Text", codec.string(), Text, fn(m) {
148+
case m { Text(s) -> Ok(s); _ -> Error(Nil) }
149+
})
150+
|> variant.unit(1, "Ping", Ping, fn(m) { m == Ping })
151+
|> variant.build()
152+
```
153+
131154
### Cluster Monitoring
132155

133156
Subscribe to cluster events (`NodeUp`, `NodeDown`) to react to node topology changes.

gleam.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ target = "erlang"
1313
gleam_stdlib = ">= 0.60.0 and < 2.0.0"
1414
gleam_erlang = ">= 1.0.0 and < 2.0.0"
1515
gleam_otp = ">= 1.0.0 and < 2.0.0"
16+
telemetry = ">= 1.0.0 and < 2.0.0"
1617

1718
[dev-dependencies]
1819
gleeunit = ">= 1.0.0 and < 2.0.0"

manifest.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ packages = [
66
{ name = "gleam_otp", version = "1.2.0", build_tools = ["gleam"], requirements = ["gleam_erlang", "gleam_stdlib"], otp_app = "gleam_otp", source = "hex", outer_checksum = "BA6A294E295E428EC1562DC1C11EA7530DCB981E8359134BEABC8493B7B2258E" },
77
{ name = "gleam_stdlib", version = "0.68.1", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "F7FAEBD8EF260664E86A46C8DBA23508D1D11BB3BCC6EE1B89B3BC3E5C83FF1E" },
88
{ name = "gleeunit", version = "1.9.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "DA9553CE58B67924B3C631F96FE3370C49EB6D6DC6B384EC4862CC4AAA718F3C" },
9+
{ name = "telemetry", version = "1.3.0", build_tools = ["rebar3"], requirements = [], otp_app = "telemetry", source = "hex", outer_checksum = "7015FC8919DBE63764F4B4B87A95B7C0996BD539E0D499BE6EC9D7F3875B79E6" },
910
]
1011

1112
[requirements]
1213
gleam_erlang = { version = ">= 1.0.0 and < 2.0.0" }
1314
gleam_otp = { version = ">= 1.0.0 and < 2.0.0" }
1415
gleam_stdlib = { version = ">= 0.60.0 and < 2.0.0" }
1516
gleeunit = { version = ">= 1.0.0 and < 2.0.0" }
17+
telemetry = { version = ">= 1.0.0 and < 2.0.0" }

0 commit comments

Comments
 (0)