Skip to content

The closest I could get to providing an user-experience like the thiserror crate for WIT generated code

License

Notifications You must be signed in to change notification settings

danbugs/wit-error-rs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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:

// wit_bindgen_rust::export!("<path>/<to>/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:

// wit_bindgen_rust::export!("<path>/<to>/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.

About

The closest I could get to providing an user-experience like the thiserror crate for WIT generated code

Topics

Resources

License

Stars

Watchers

Forks

Languages