https://github.com/gistyr/better-assert
Rust assertion functions and panic with built-in logging
https://github.com/gistyr/better-assert
assert assert-eq assert-ne debug debug-assert file-logging logging network-logging panic testing
Last synced: 3 months ago
JSON representation
Rust assertion functions and panic with built-in logging
- Host: GitHub
- URL: https://github.com/gistyr/better-assert
- Owner: Gistyr
- License: apache-2.0
- Created: 2025-05-20T11:52:19.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2025-05-20T22:07:07.000Z (8 months ago)
- Last Synced: 2025-09-16T08:19:32.877Z (4 months ago)
- Topics: assert, assert-eq, assert-ne, debug, debug-assert, file-logging, logging, network-logging, panic, testing
- Language: Rust
- Homepage: https://crates.io/crates/better-assert
- Size: 40 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
# better-assert
#### Assertion helpers with built-in logging powered by [better-logger](https://crates.io/crates/better-logger)
## ⚠️ Is this crate right for you?
> #### Dependency note
> **See [better-logger](https://crates.io/crates/better-logger) before you use this crate**
>
> `better-assert` incorporates `better-logger` as its logging facade. Any project using `better-assert` must do the same.
> `better-logger` has terminal, file, and network logging functionality.
### Why you might need it
| Scenario | Pain point with plain `assert!` | How `better-assert` helps |
|----------|---------------------------------|---------------------------|
| **WASM front-end** | An `assert_eq!` fails silently in a user’s browser, you never see it | `log_assert_eq()` sends a log entry to your backend *before* the panic |
| **Headless server / embedded** | A `panic!` crash disappears into `/dev/null` or an unknown serial console | `log_panic()` sends the details to a file, syslog, or over-the-wire sink |
# HOW TO USE
## 😺 ONE: Declare Feature
```rust
/* no default feature enabled (enabling both at once won't compile) */
better-assert = { version = "0.3.2", features = ["native"] }
better-assert = { version = "0.3.2", features = ["wasm"] }
```
## 🦮 TWO: Incorporate better-logger
#### See the [better-logger docs](https://crates.io/crates/better-logger) for the quick-start
```rust
/* Also has no default feature enabled (enabling both at once won't compile) */
better-logger = { version = "1.0.3", features = ["native"] }
better-logger = { version = "1.0.3", features = ["wasm"] }
```
## 💻 THREE: Use
```rust
use better_assert::*;
let left = "value".to_string();
let right = "value".to_string();
log_assert_eq(&left, &right); // enabled in all builds
log_assert_ne(&left, &right);
debug_log_assert_eq(&left, &right); // enabled only in debug builds
debug_log_assert_ne(&left, &right);
log_panic(); // always logs, then panics
```
# License
© 2025 Gistyr LLC
This project, **better-assert**, is dual-licensed under your choice of:
- **Apache License 2.0**
See the [LICENSE-APACHE](LICENSE-APACHE) file or view it online at
- **MIT License**
See the [LICENSE-MIT](LICENSE-MIT) file or view it online at