Skip to content

Commit f81b454

Browse files
committed
Expand on readme...
1 parent 274a11a commit f81b454

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

README.md

+21-3
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,35 @@ It only works with enums where each variant has a single unnamed element, and if
77
The most basic use is to provide conversions between the enum cases and the enum type itself. You could achieve something similar with the popular [derive_more] crate.
88

99
```rust
10-
# struct PutRequest;
11-
# struct GetRequest;
1210
#[enum_conversions()]
13-
enum Protocol {
11+
enum Request {
1412
Get(GetRequest),
1513
Put(PutRequest),
1614
}
1715
```
1816

1917
A more advanced use, and the reason for this crate to exist, is to provide conversions between enum variants and any type that itself has a *conversion* to the enum. This allows to use nested enums, like you would in a complex protocol that has several subsystems.
2018

19+
```rust
20+
#[enum_conversions(Request)]
21+
enum StoreRequest {
22+
Get(GetRequest),
23+
Put(PutRequest),
24+
}
25+
26+
#[enum_conversions(Request)]
27+
enum NetworkRequest {
28+
Ping(PingRequest),
29+
}
30+
31+
#[enum_conversions()]
32+
enum Request {
33+
Store(StoreRequest),
34+
Network(NetworkRequest),
35+
}
36+
```
37+
38+
Here we define conversions from `GetRequest` to `StoreRequest`, from `StoreRequest` to `Request`, and then directly from `GetRequest` to `Request`, and corresponding [TryFrom] conversions in the other direction.
2139

2240
## Generated conversions
2341

0 commit comments

Comments
 (0)