https://github.com/randombit/assert_ok
Rust assert_ok macro
https://github.com/randombit/assert_ok
Last synced: 9 months ago
JSON representation
Rust assert_ok macro
- Host: GitHub
- URL: https://github.com/randombit/assert_ok
- Owner: randombit
- Created: 2022-03-17T13:30:23.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2022-11-17T19:06:56.000Z (about 3 years ago)
- Last Synced: 2025-02-05T22:46:59.465Z (11 months ago)
- Language: Rust
- Size: 6.84 KB
- Stars: 5
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
assert_ok
============
[](https://crates.io/crates/assert_ok)
[](https://docs.rs/assert_ok)
This crate contains a macro `assert_ok` which takes an expression and
if the expression evaluates to an `Err`, panics with a useful
message. If in contrast the expression evaluates to `Ok(v)` then it
returns the value `v`.
This is commonly useful in tests. Instead of
```
let z = foo(arg1, arg2).unwrap();
```
or
```
let z = foo(arg1, arg2).expect("foo failed");
```
use
```
let z = assert_ok!(foo(arg1, arg2));
```
It's easier to understand (IMO) and more importantly provides a much
more useful error message in the case that it fails.
There is a similar macro in Tokio, however for libraries or applications
that don't use Tokio, pulling it in for a single macro doesn't make sense.