Crates.io | error-tree |
lib.rs | error-tree |
version | 0.3.7 |
source | src |
created_at | 2024-05-05 21:32:30.915319 |
updated_at | 2024-10-05 04:00:05.778667 |
description | This crate let's us use the `error_tree!` proc macro for ergonomic error hierarchy definition |
homepage | |
repository | https://github.com/klebs6/klebs-general |
max_upload_size | |
id | 1230559 |
size | 50,115 |
error_tree
is a Rust procedural macro crate designed to simplify error handling in Rust applications. It allows you to define complex error hierarchies in a clean and structured way, making your error handling logic both more robust and easier to maintain.
From
implementations for error conversions.Add error_tree
to your Cargo.toml
file under [dependencies]
:
[dependencies]
error_tree = "0.1.0"
Here's a basic example of how to use error_tree
:
use error_tree::error_tree;
error_tree!{
// Enumerate possible errors for capturing audio.
pub enum PassiveAudioCaptureError {
FormatError,
DeviceError(DeviceError),
IOError(IOError),
WavError(WavError),
HostError(HostError),
StreamOrChannelError(StreamOrChannelError),
}
pub enum MonitorAllInputsError {
DeviceError(DeviceError),
}
pub enum StreamOrChannelError {
StreamError(StreamError),
ChannelError(ChannelError),
}
pub enum IOError {
Basic(std::io::Error),
}
pub enum ChannelError {
ChannelRecvError(mpsc::RecvError),
}
pub enum StreamError {
StreamError(cpal::StreamError),
PauseStreamError(cpal::PauseStreamError),
BuildStreamError(cpal::BuildStreamError),
PlayStreamError(cpal::PlayStreamError),
SupportedStreamConfigsError(cpal::SupportedStreamConfigsError),
DefaultStreamConfigError(cpal::DefaultStreamConfigError),
}
pub enum DeviceError {
DeviceNotAvailable {
device_name: String,
},
Basic(cpal::DevicesError),
NameError(cpal::DeviceNameError),
}
pub enum WavError {
Hound(hound::Error),
}
pub enum HostError {
HostUnavailable(cpal::HostUnavailable),
}
}
This will automatically generate the necessary From
implementations for error conversions within your defined hierarchy.
Contributions to error_tree
are welcome! Please read our CONTRIBUTING.md for guidelines on how to contribute.
This crate is distributed under the terms of MIT License.