1#![doc = include_str!("../README.md")]
2use std::collections::HashMap;
3
4pub use restcrab_macros::*;
5
6#[derive(Debug, snafu::Snafu)]
7pub enum Error {
8 #[snafu(display("Empty response body"))]
9 EmptyBody,
10
11 #[snafu(display("Expected empty response body"))]
12 NoEmptyBody,
13}
14
15pub struct Request<T> {
16 pub method: http::Method,
17 pub url: http::Uri,
18 pub headers: HashMap<String, String>,
19 pub queries: HashMap<String, String>,
20 pub body: Option<T>,
21 pub expect_body: bool,
22}
23
24pub trait Restcrab
25where
26 Self: Sized,
27{
28 type Error: std::error::Error + std::fmt::Debug + From<Error> + 'static + Send + Sync;
29 type Options;
30 type Crab: Restcrab;
31
32 fn call<REQ: serde::Serialize, RES: for<'de> serde::Deserialize<'de>>(&self, request: Request<REQ>) -> Result<Option<RES>, Self::Error>;
33 fn from_options(options: Self::Options) -> Result<Self, Self::Error>;
34 fn options(&self) -> &Self::Options;
35 fn options_mut(&mut self) -> &mut Self::Options;
36}
37
38pub mod crabs;
39
40pub use http;