Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gajop/ctrl_macros
https://github.com/gajop/ctrl_macros
Last synced: 3 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/gajop/ctrl_macros
- Owner: gajop
- License: other
- Created: 2022-08-02T16:43:20.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2022-08-02T16:59:19.000Z (over 2 years ago)
- Last Synced: 2024-10-13T15:10:56.493Z (about 1 month ago)
- Language: Rust
- Size: 2.93 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# README
Control macros for `Option` and `Result`.
Helps you change this:
```rust
fn returns_early_with_value(input: Result) {
// Early return when something is wrong.
let input: i32 = match input {
Ok(value) => value,
Err(_) => return,
};// Use it normally below...
println!("Input is: {}", input);
}
```into
```rust
use ctrl_macros::{ok_or_return};fn returns_early_with_value(input: Result) {
let input: i32 = ok_or_return!(input);
println!("Input is: {}", input);
}
```## Examples
```rust
let x = ok_or!(x, return 42);
``````rust
for i in 0..5 {
let x = ok_or_continue!(x);
}
``````rust
for i in 0..5 {
let x = ok_or_break!(x);
}
```and `some_or` equivalents
```rust
some_or!
some_or_return!
some_or_continue!
some_or_break!
```# License
`ctrl_macros` is dual licensed under either:
- MIT license ([LICENSE-MIT](docs/LICENSE-MIT) or http://opensource.org/licenses/MIT)
- Apache License, Version 2.0, ([LICENSE-APACHE](docs/LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
at your option.Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.