https://github.com/playxe/const-if
https://github.com/playxe/const-if
Last synced: 8 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/playxe/const-if
- Owner: playXE
- License: mit
- Created: 2019-04-28T12:09:26.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2019-06-19T20:08:38.000Z (almost 6 years ago)
- Last Synced: 2024-03-15T11:04:35.420Z (about 1 year ago)
- Language: Rust
- Size: 4.88 KB
- Stars: 2
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# const-if
This crate adds if-elif-else expression into your constant functions
# Why
Since `if` expression not implemented in current implementation of const-fn I decided to create this macro# Example
```rust
const fn min(x: i32, y: i32) -> i32 {
const_if!(x < y => x;y)
}
```
```rust
const fn int_to_str(i: i32) -> &'static str {
const_if!(
i == 0 => "Zero";
elif i == 1 => "One";
elif i == 2 => "Two";
elif i == 3 => "Three";
elif i == 4 => "Four";
elif i == 5 => "Five";
elif i == 6 => "Six";
elif i == 7 => "Seven";
elif i == 8 => "Eight";
elif i == 9 => "Nine";
elif i == 10 => "Ten";
else "Unknown"
)
}```