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: src/attributes/testing.md
-46
Original file line number
Diff line number
Diff line change
@@ -81,52 +81,6 @@ fn mytest() {
81
81
assert_eq!(1, 2, "values don't match");
82
82
}
83
83
```
84
-
## Different panic strategies
85
-
86
-
The `cfg_panic` feature makes it possible to exercise different lines of code depending on the panic strategy.
87
-
The possible value is either `unwind` or `abort`.
88
-
89
-
The following is a playful example on choosing the right beverage.
90
-
91
-
```rust
92
-
93
-
#[cfg(panic ="unwind")]
94
-
fnah(){ println!("Spit it out!!!!");}
95
-
96
-
#[cfg(not(panic="unwind"))]
97
-
fnah(){ println!("This is not your party. Run!!!!");}
98
-
99
-
fndrink(beverage:&str){
100
-
ifbeverage=="lemonade"{ ah();}
101
-
else{println!("Some refreshing {} is all I need.", beverage);}
102
-
}
103
-
104
-
fnmain(){
105
-
drink("water");
106
-
drink("lemonade");
107
-
}
108
-
```
109
-
110
-
Here is the same example rewritten.
111
-
```rust
112
-
113
-
fndrink(beverage:&str) {
114
-
// You shouldn't drink too much sugary beverages.
115
-
ifbeverage=="lemonade" {
116
-
ifcfg!(panic="abort"){ println!("This is not your party. Run!!!!");}
117
-
else{ println!("Spit it out!!!!");}
118
-
}
119
-
else{ println!("Some refreshing {} is all I need.", beverage); }
120
-
}
121
-
122
-
fnmain() {
123
-
drink("water");
124
-
drink("lemonade");
125
-
}
126
-
```
127
-
128
-
Note that when the code is compiled with a certain panic strategy it still might do something different if another crate was compiled with a different strategy.
129
-
For instance, if `#[cfg(panic = "unwind")]` is set to `true` and a crate is compiled with`-C panic=abort`.
0 commit comments