| Crates.io | chewie-macros |
| lib.rs | chewie-macros |
| version | 0.1.1 |
| created_at | 2025-12-19 10:10:42.321006+00 |
| updated_at | 2025-12-19 10:24:02.975348+00 |
| description | Procedural macros for chewie-auth ecosystem |
| homepage | |
| repository | https://github.com/chewie-rs/chewie-macros |
| max_upload_size | |
| id | 1994503 |
| size | 46,405 |
Procedural macros for the chewie-auth ecosystem.
This crate provides compile-time code generation to reduce boilerplate and improve developer experience.
define_boxed_error!Generates a type-erased error type with downcast support.
use chewie_macros::define_boxed_error;
define_boxed_error! {
/// HTTP client error.
pub HttpError {
display: "HTTP error",
}
}
This generates:
Box<dyn Error> field (with Send + Sync bounds when send feature is enabled)Display and Error trait implementationsdowncast_ref<E>() and downcast<E>() methods for error inspectioninner() method to access the underlying erroruse chewie_macros::define_boxed_error;
define_boxed_error! {
/// Error returned by the token validation layer.
pub TokenError {
display: "token validation failed",
}
}
// Create from any error type
fn validate_token(token: &str) -> Result<(), TokenError> {
let parsed: serde_json::Value = serde_json::from_str(token)
.map_err(|e| TokenError { source: Box::new(e) })?;
Ok(())
}
// Downcast to inspect the underlying error
fn handle_error(err: TokenError) {
if let Some(json_err) = err.downcast_ref::<serde_json::Error>() {
eprintln!("JSON parsing failed: {}", json_err);
}
}
You can specify a custom box error path if you have your own error type:
use chewie_macros::define_boxed_error;
// Assuming you have a custom BoxError type alias
type BoxError = Box<dyn std::error::Error + Send + Sync>;
define_boxed_error! {
/// Client error with custom box type.
pub ClientError {
display: "client error",
box_error_path: BoxError,
}
}
send - Controls Send + Sync bounds in generated code. Automatically enabled by build.rs for non-browser targets (native and WASI). Browser WASM targets (wasm32-unknown-unknown) do not enable this feature.Add to your Cargo.toml:
[dependencies]
chewie-macros = "0.1"
Licensed under either of:
at your option.