Debian Codegraph @

debian/missing-sources/cfg-if/README.md

raw symbols SCIP
1 # cfg-if
2
3 [Documentation](https://docs.rs/cfg-if)
4
5 A macro to ergonomically define an item depending on a large number of #[cfg]
6 parameters. Structured like an if-else chain, the first matching branch is the
7 item that gets emitted.
8
9 ```toml
10 [dependencies]
11 cfg-if = "1.0"
12 ```
13
14 ## Example
15
16 ```rust
17 cfg_if::cfg_if! {
18 if #[cfg(unix)] {
19 fn foo() { /* unix specific functionality */ }
20 } else if #[cfg(target_pointer_width = "32")] {
21 fn foo() { /* non-unix, 32-bit functionality */ }
22 } else {
23 fn foo() { /* fallback implementation */ }
24 }
25 }
26
27 fn main() {
28 foo();
29 }
30 ```
31 The `cfg_if!` block above is expanded to:
32 ```rust
33 #[cfg(unix)]
34 fn foo() { /* unix specific functionality */ }
35 #[cfg(all(target_pointer_width = "32", not(unix)))]
36 fn foo() { /* non-unix, 32-bit functionality */ }
37 #[cfg(not(any(unix, target_pointer_width = "32")))]
38 fn foo() { /* fallback implementation */ }
39 ```
40
41 # License
42
43 This project is licensed under either of
44
45 * Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
46 https://www.apache.org/licenses/LICENSE-2.0)
47 * MIT license ([LICENSE-MIT](LICENSE-MIT) or
48 https://opensource.org/licenses/MIT)
49
50 at your option.
51
52 ### Contribution
53
54 Unless you explicitly state otherwise, any contribution intentionally submitted
55 for inclusion in `cfg-if` by you, as defined in the Apache-2.0 license, shall be
56 dual licensed as above, without any additional terms or conditions.