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