Skip to content

Commit 9ab6f9b

Browse files
authored
Merge pull request #94 from http-rs/client-server-traits
Add Client and Server traits
2 parents 403d5e2 + 7153bdd commit 9ab6f9b

File tree

5 files changed

+60
-1
lines changed

5 files changed

+60
-1
lines changed

Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,14 @@ authors = ["Yoshua Wuyts <[email protected]>"]
1111
readme = "README.md"
1212
edition = "2018"
1313

14+
[package.metadata.docs.rs]
15+
features = ["docs"]
16+
rustdoc-args = ["--cfg", "feature=\"docs\""]
17+
1418
[features]
1519
default = []
20+
docs = ["unstable"]
21+
unstable = []
1622
hyperium_http = ["http"]
1723

1824
[dependencies]

src/client.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
use std::fmt::Debug;
2+
use std::future::Future;
3+
use std::pin::Pin;
4+
5+
use crate::{Request, Response, Result};
6+
7+
type BoxFuture<'a, T> = Pin<Box<dyn Future<Output = T> + 'a + Send>>;
8+
9+
/// An HTTP client.
10+
#[cfg(feature = "unstable")]
11+
#[cfg_attr(feature = "docs", doc(cfg(unstable)))]
12+
pub trait Client: Debug + Unpin + Send + Sync + Clone + 'static {
13+
/// Send an HTTP request from the client.
14+
fn send_req(&self, req: Request) -> BoxFuture<'static, Result<Response>>;
15+
}

src/lib.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,9 @@
9595
9696
#![forbid(rust_2018_idioms)]
9797
#![deny(missing_debug_implementations, nonstandard_style)]
98-
#![warn(missing_docs, missing_doc_code_examples, unreachable_pub)]
98+
#![warn(missing_docs, unreachable_pub)]
9999
#![cfg_attr(test, deny(warnings))]
100+
#![cfg_attr(feature = "docs", feature(doc_cfg))]
100101

101102
/// HTTP cookies.
102103
pub mod cookies {
@@ -111,6 +112,9 @@ pub mod url {
111112
};
112113
}
113114

115+
#[macro_use]
116+
mod utils;
117+
114118
pub mod headers;
115119
pub mod mime;
116120

@@ -125,6 +129,14 @@ mod status_code;
125129
mod type_map;
126130
mod version;
127131

132+
cfg_unstable! {
133+
mod client;
134+
mod server;
135+
136+
pub use client::Client;
137+
pub use server::Server;
138+
}
139+
128140
pub use body::Body;
129141
pub use error::{Error, Result};
130142
pub use method::Method;

src/server.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
use std::fmt::Debug;
2+
use std::future::Future;
3+
use std::pin::Pin;
4+
5+
use crate::{Request, Response, Result};
6+
7+
type BoxFuture<'a, T> = Pin<Box<dyn Future<Output = T> + 'a + Send>>;
8+
9+
/// An HTTP server.
10+
#[cfg(feature = "unstable")]
11+
#[cfg_attr(feature = "docs", doc(cfg(unstable)))]
12+
pub trait Server: Debug + Unpin + Send + Sync + Clone + 'static {
13+
/// Receive an HTTP request on the server.
14+
fn recv_req(&self, req: Request) -> BoxFuture<'static, Result<Response>>;
15+
}

src/utils.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/// Declares unstable items.
2+
#[doc(hidden)]
3+
macro_rules! cfg_unstable {
4+
($($item:item)*) => {
5+
$(
6+
#[cfg(feature = "unstable")]
7+
#[cfg_attr(feature = "docs", doc(cfg(unstable)))]
8+
$item
9+
)*
10+
}
11+
}

0 commit comments

Comments
 (0)