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
Copy file name to clipboardExpand all lines: README.md
+18-2Lines changed: 18 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -41,8 +41,24 @@ Here we define conversions from `GetRequest` to `StoreRequest`, from `StoreReque
41
41
42
42
The generated [From] conversions are straightforward. Obviously it is always possible to convert from an enum case to the enum itself.
43
43
44
-
We also generate [TryFrom] conversions from the enum to each variant, as well as from a reference to the enum to a reference to the variant. The conversions that take a value are different than the ones from [derive_more]: they return
45
-
the unmodified input in the error case, allowing to chain conversion attempts.
44
+
We also generate [TryFrom] conversions from the enum to each variant, as well as from a reference to the enum to a reference to the variant.
45
+
46
+
The conversions that take a value are different than the ones from [derive_more]: they return the unmodified input in the error case, allowing to chain conversion attempts.
47
+
48
+
```rust
49
+
letrequest=...
50
+
matchGetRequest::try_from(request) {
51
+
Ok(get) =>// handle get request
52
+
Err(request) => {
53
+
// I still got the request and can try something else
54
+
matchPutRequest::try_from(request) {
55
+
...
56
+
}
57
+
}
58
+
}
59
+
```
60
+
61
+
The conversions that take a reference just return a `&'static str` as the error type. References are `Copy`, so we can always retry anyway.
0 commit comments