added documentation for cfg_panic
@@ -81,6 +81,50 @@ fn mytest() {
assert_eq!(1, 2, "values don't match");
}
```
+### Different panic strategies
+
+The `cfg_panic` feature makes it possible to exercise different lines of code depending on the panic strategy.
+The possible value is either `unwind` or `abort`.
+The following is a playful example on choosing the right beverage.
+
+```toml
+#![feature(cfg_panic)]
+
+#[cfg(panic = "unwind")]
+fn ah(){ println!("Spit it out!!!!");}
+
+#[cfg(not(panic="unwind"))]
+fn ah(){ println!("This is not your party. Run!!!!");}
+
+fn drink(beverage: &str){
+ if beverage == "lemonade"{ ah();}
+ else{println!("Some refreshing {} is all I need.", beverage);}
+}
+
+fn main(){
+ drink("water");
+ drink("lemonade");
+}
+```
+
+Here is the same example rewritten.
+```toml
+#![feature(cfg_panic)]
+
+fn drink(beverage: &str) {
+ // You shouldn't drink too much sugary beverages.
+ if beverage == "lemonade" {
+ if cfg!(panic="abort"){ println!("This is not your party. Run!!!!");}
+ else{ println!("Spit it out!!!!");}
+ }
+ else{ println!("Some refreshing {} is all I need.", beverage); }
+}
+
+fn main() {
+ drink("water");
+ drink("lemonade");
+}
+```
[_MetaListNameValueStr_]: ../attributes.md#meta-item-attribute-syntax
[_MetaNameValueStr_]: ../attributes.md#meta-item-attribute-syntax
