File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -41,6 +41,33 @@ type that wraps platform-specific return types. That has `SUCCESS` and `FAILURE`
41
41
implements ` From<u8> ` for more arbitrary values. The ` Termination ` trait can also be implemented for
42
42
your own types, allowing you to customize any kind of reporting before converting to an ` ExitCode ` .
43
43
44
+ For example, here's a type-safe way to write exit codes for a ` git bisect run ` script:
45
+
46
+ ``` rust
47
+ use std :: process :: {ExitCode , Termination };
48
+
49
+ #[repr(u8 )]
50
+ pub enum GitBisectResult {
51
+ Good = 0 ,
52
+ Bad = 1 ,
53
+ Skip = 125 ,
54
+ Abort = 255 ,
55
+ }
56
+
57
+ impl Termination for GitBisectResult {
58
+ fn report (self ) -> ExitCode {
59
+ // Maybe print a message here
60
+ ExitCode :: from (self as u8 )
61
+ }
62
+ }
63
+
64
+ fn main () -> GitBisectResult {
65
+ std :: panic :: catch_unwind (|| {
66
+ todo! (" test the commit" )
67
+ }). unwrap_or (GitBisectResult :: Abort )
68
+ }
69
+ ```
70
+
44
71
### More capabilities for ` const fn `
45
72
46
73
Several incremental features have been stabilized in this release to enable more functionality in
You can’t perform that action at this time.
0 commit comments