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: impl/doc/try_unwrap.md
+20-3Lines changed: 20 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,18 +2,22 @@
2
2
3
3
This works almost like `Unwrap`.
4
4
When an enum is decorated with `#[derive(TryUnwrap)]`, for each variant `foo` in the enum, with fields `(a, b, c, ...)` a public instance method `try_unwrap_foo(self) -> Result<(a, b, c, ...), TryUnwrapError<Self>>` is generated.
5
+
5
6
If you don't want the `try_unwrap_foo` method generated for a variant, you can put the `#[try_unwrap(ignore)]` attribute on that variant.
6
-
If you want to treat a reference, you can put the `#[try_unwrap(ref)]` attribute on the enum declaration or that variant, then `try_unwrap_foo_ref(self) -> Result<(&a, &b, &c, ...), TryUnwrapError<&Self>>` will be generated. You can also use mutable references by putting `#[unwrap(ref_mut)]`.
7
+
8
+
By using `#[try_unwrap(owned, ref, ref_mut)]` it's possible to generate methods implementation for reference types as well (like `try_unwrap_foo_ref(&self) -> Result<(&a, &b, &c, ...), TryUnwrapError<&Self>>`).
9
+
You can pick any combination of `owned`, `ref` and `ref_mut`. If that's not provided the default is `#[try_unwrap(owned)]`.
10
+
7
11
However, unlike `Unwrap`, it does not panic if the conversion fails. Also, values that fail to convert are not dropped but returned as an `Err`.
Copy file name to clipboardExpand all lines: impl/doc/unwrap.md
+19-3Lines changed: 19 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,8 +1,11 @@
1
1
# What `#[derive(Unwrap)]` generates
2
2
3
3
When an enum is decorated with `#[derive(Unwrap)]`, for each variant `foo` in the enum, with fields `(a, b, c, ...)` a public instance method `unwrap_foo(self) -> (a, b, c, ...)` is generated.
4
+
4
5
If you don't want the `unwrap_foo` method generated for a variant, you can put the `#[unwrap(ignore)]` attribute on that variant.
5
-
If you want to treat a reference, you can put the `#[unwrap(ref)]` attribute on the enum declaration or that variant, then `unwrap_foo_ref(self) -> (&a, &b, &c, ...)` will be generated. You can also use mutable references by putting `#[unwrap(ref_mut)]`.
6
+
7
+
By using `#[unwrap(owned, ref, ref_mut)]` it's possible to generate methods implementation for reference types as well (like `unwrap_foo_ref(&self) -> (&a, &b, &c, ...)`).
8
+
You can pick any combination of `owned`, `ref` and `ref_mut`. If that's not provided the default is `#[unwrap(owned)]`.
6
9
7
10
8
11
@@ -11,10 +14,10 @@ If you want to treat a reference, you can put the `#[unwrap(ref)]` attribute on
0 commit comments