Skip to content

Commit

Permalink
Write up README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
benfrankel committed Aug 1, 2024
1 parent 1d24140 commit 98a6ed8
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,31 @@
[![Docs](https://docs.rs/tiny_bail/badge.svg)](https://docs.rs/tiny_bail/latest/tiny_bail/)
[![License](https://img.shields.io/badge/license-MIT%2FApache-blue.svg)](https://github.com/benfrankel/tiny_bail)

TODO: Sample code.
This crate provides four failure-skipping macros: `r!`, `rq!`, `c!`, and `cq!`; along with their long-form aliases
`or_return!`, `or_return_quiet!`, `or_continue!`, and `or_continue_quiet!`, respectively.

The macros support handle both `Option` and `Result` types out-of-the-box. This can be extended by implementing the
`Success` trait for other types.

You can provide a return value as an optional first argument to the macro, or you can omit it to default to
`Default::default()`—which also works in functions with no return value.

# Example

```rust
/// Increment the last number of a list, or warn if it's empty.
fn increment_last(list: &mut [usize]) {
// With `r!`:
*r!(list.last_mut()) += 1;

// Without `r!`:
if let Some(x) = list.last_mut() {
*x += 1;
} else {
warn!("Empty list");
return;
}
}
```

# License
Expand Down

0 comments on commit 98a6ed8

Please sign in to comment.