Skip to content

Commit 464866f

Browse files
authored
Add files via upload
1 parent 14bb695 commit 464866f

File tree

1 file changed

+0
-46
lines changed

1 file changed

+0
-46
lines changed

src/attributes/testing.md

-46
Original file line numberDiff line numberDiff line change
@@ -81,52 +81,6 @@ fn mytest() {
8181
assert_eq!(1, 2, "values don't match");
8282
}
8383
```
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-
fn ah(){ println!("Spit it out!!!!");}
95-
96-
#[cfg(not(panic="unwind"))]
97-
fn ah(){ println!("This is not your party. Run!!!!");}
98-
99-
fn drink(beverage: &str){
100-
if beverage == "lemonade"{ ah();}
101-
else{println!("Some refreshing {} is all I need.", beverage);}
102-
}
103-
104-
fn main(){
105-
drink("water");
106-
drink("lemonade");
107-
}
108-
```
109-
110-
Here is the same example rewritten.
111-
```rust
112-
113-
fn drink(beverage: &str) {
114-
// You shouldn't drink too much sugary beverages.
115-
if beverage == "lemonade" {
116-
if cfg!(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-
fn main() {
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`.
13084

13185
[_MetaListNameValueStr_]: ../attributes.md#meta-item-attribute-syntax
13286
[_MetaNameValueStr_]: ../attributes.md#meta-item-attribute-syntax

0 commit comments

Comments
 (0)