From e6db6bcc682392d965743cb38ae739ce96797f47 Mon Sep 17 00:00:00 2001 From: buckn Date: Wed, 24 Sep 2025 12:03:17 -0400 Subject: [PATCH] anyhow impl --- Cargo.lock | 7 +++++++ Cargo.toml | 1 + src/lib.rs | 15 +++++++-------- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1498944..7aa1ceb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -137,6 +137,12 @@ dependencies = [ "alloc-no-stdlib", ] +[[package]] +name = "anyhow" +version = "1.0.100" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a23eb6b1614318a8071c9b2521f36b424b2c83db5eb3a0fead4a6c0809af6e61" + [[package]] name = "async-trait" version = "0.1.89" @@ -518,6 +524,7 @@ dependencies = [ name = "http_core" version = "0.1.0" dependencies = [ + "anyhow", "async-trait", "awc", "serde", diff --git a/Cargo.toml b/Cargo.toml index f9fb6ac..83563fa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,6 +6,7 @@ description = "Core traits and types for building API clients with http_derive" license = "MIT OR Apache-2.0" [dependencies] +anyhow = "1.0.100" async-trait = "0.1" awc = "3" serde = { version = "1", features = ["derive"] } diff --git a/src/lib.rs b/src/lib.rs index ddea091..09590db 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,9 +1,10 @@ use async_trait::async_trait; +use anyhow::Result; use serde::{Deserialize, Serialize}; use std::collections::HashMap; use std::path::Path; -use std::{ fs, fmt }; use std::sync::Arc; +use std::{fmt, fs}; /// A trait every API request type should implement (via macro). /// Provides info about the HTTP protocol, URLs, and supported methods. @@ -23,7 +24,7 @@ pub trait HasHttp { #[async_trait] pub trait Queryable: HasHttp + Send + Sync { type R; - type E: std::error::Error + 'static; // Keep trait bound + type E: std::error::Error + Send + Sync + 'static; // Keep trait bound async fn send( &self, @@ -31,15 +32,14 @@ pub trait Queryable: HasHttp + Send + Sync { sandbox: bool, method_override: Option<&str>, headers: Option>, - ) -> Result; + ) -> Result; } - /// Trait implemented by your auto-generated API dispatcher enums. /// This allows you to batch or route requests by API type. #[async_trait] pub trait ApiDispatch { - type E: std::error::Error + 'static; + type R; async fn send_all( &self, @@ -48,7 +48,7 @@ pub trait ApiDispatch { override_url: Option<&str>, sandbox: bool, method_override: Option<&str>, - ) -> Result<(), Self::E>; + ) -> Result>; } @@ -73,7 +73,7 @@ impl Keys { /// Loads API keys from ~/.config/keys or fallback ./keys directory. /// Each `.toml` file should contain a `Key { key, secret }` struct. /// The filename (without `.toml`) becomes the key name in the map. -pub fn load_api_keys() -> Result> { +pub fn load_api_keys() -> Result { let home_dir = std::env::var("HOME")?; let config_dir = Path::new(&home_dir).join(".config/keys"); let fallback_dir = Path::new("keys"); @@ -115,4 +115,3 @@ impl fmt::Display for ConversionError { impl std::error::Error for ConversionError {} unsafe impl Send for ConversionError {} unsafe impl Sync for ConversionError {} -