https://github.com/danbugs/wit-error-rs
The closest I could get to providing an user-experience like the thiserror crate for WIT generated code
https://github.com/danbugs/wit-error-rs
rust webassembly wit
Last synced: 21 days ago
JSON representation
The closest I could get to providing an user-experience like the thiserror crate for WIT generated code
- Host: GitHub
- URL: https://github.com/danbugs/wit-error-rs
- Owner: danbugs
- License: agpl-3.0
- Created: 2022-06-22T21:37:01.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2022-06-22T23:46:54.000Z (almost 4 years ago)
- Last Synced: 2025-03-12T03:33:40.398Z (over 1 year ago)
- Topics: rust, webassembly, wit
- Language: Rust
- Homepage:
- Size: 18.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# `wit-error-rs`
This is the closest I could get to an user-experience similar to the `thiserror` Rust crate.
## How To Use
In your `Cargo.toml`, add:
```
wit-error-rs = { git = "https://github.com/danbugs/wit-error-rs", rev = "05362f1a4a3a9dc6a1de39195e06d2d5d6491a5e" }
```
If, in your wit, you have type that you want to classify as an Error type (i.e., should implement `std::error::Error`), like:
```
// file error.wit
variant error {
error-with-description(string)
}
```
You can use `wit-error-rs` to classify it that way, like so:
```rs
// wit_bindgen_rust::export!("//error.wit"); <- assumed
wit_error-rs::impl_error!(error::Error);
```
In addition, you can convert from things like `anyhow::Error` to your own `error::Error`, like so:
```rs
// wit_bindgen_rust::export!("//error.wit"); <- assumed
wit_error-rs::impl_from!(anyhow::Error, error::Error::ErrorWithDescription);
```
For a more detailed explanation and usage, refer to the examples directory.