conditional/lib.rs
1// Copyright 2019 Alexander Krivács Schrøder
2//
3// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
4// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
5// http://opensource.org/licenses/MIT>, at your option. This file may not be
6// copied, modified, or distributed except according to those terms.
7
8use proc_macro_hack::proc_macro_hack;
9
10/// Lets you use the syntax of the conditional operator in Rust. Also known as the ternary operator.
11///
12/// # Examples
13/// ```
14/// # #[macro_use] extern crate conditional;
15/// #
16/// # fn main() {
17/// let x = conditional!(69 > 42 ? "hello" : "world");
18/// assert_eq!(x, "hello");
19/// # }
20/// ```
21/// ```
22/// # #[macro_use] extern crate conditional;
23/// #
24/// # fn main() -> Result<(), String> {
25/// let r: Result<i32, String> = Ok(5);
26/// // More complicated expressions are supported, but you might have to use
27/// // parentheses to satisfy the macro parser
28/// let x = conditional!((r? > 42) ? "hello" : "world");
29/// assert_eq!(x, "world");
30/// # Ok(())
31/// # }
32/// ```
33/// ```
34/// # #[macro_use] extern crate conditional;
35/// #
36/// # fn main() -> Result<(), String> {
37/// // More complicated expressions are supported, but you might have to use
38/// // parentheses to satisfy the macro parser
39/// let x = conditional!(("3".parse::<i32>().map_err(|e| e.to_string())? > 42)
40/// ? "hello" : "world");
41/// assert_eq!(x, "world");
42/// # Ok(())
43/// # }
44/// ```
45#[proc_macro_hack]
46pub use conditional_impl::conditional;