Crates.io | string_error_wrap |
lib.rs | string_error_wrap |
version | 1.0.1 |
source | src |
created_at | 2024-08-30 17:59:25.065195 |
updated_at | 2024-08-31 13:15:12.026897 |
description | Simple crate providing a macro for an error type wrapping a String. |
homepage | |
repository | https://github.com/taitep/string_error_wrap |
max_upload_size | |
id | 1358005 |
size | 4,767 |
string_error_wrap
Crate to simplify making error types wrapping String
Useful when a library uses String
errors but your app
uses something like anyhow
.
To use the crate add the crate to the project using cargo
(either manually in Cargo.toml
or using cargo add string_error_wrap
)
Then you can define a new String
-wrapping error type like this
(replacing Name with what you want the name of the type to be):
string_error_wrap::wrapper_gen!(Name);
This type implements Error
, Debug
, Clone
and From<String>
.
It is intended to be used using Result::map_err(YourError::from)
,
which will convert any errors from a String to this type, but may of course
also be used in other ways.