File: derive_decode_scalar.md

package info (click to toggle)
rust-knuffel-derive 3.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 240 kB
  • sloc: makefile: 2
file content (30 lines) | stat: -rw-r--r-- 604 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
Currently `DecodeScalar` derive is only implemented for enums

# Enums

Only enums that contain no data are supported:
```rust
#[derive(knuffel::DecodeScalar)]
enum Color {
    Red,
    Blue,
    Green,
    InfraRed,
}
```

This will match scalar values in `kebab-case`. For example, this node decoder:
```
# #[derive(knuffel::DecodeScalar)]
# enum Color { Red, Blue, Green, InfraRed }
#[derive(knuffel::Decode)]
struct Document {
    #[knuffel(child, unwrap(arguments))]
    all_colors: Vec<Color>,
}
```

Can be populated from the following text:
```kdl
all-colors "red" "blue" "green" "infra-red"
```