Skip to content

Commit 2d2e112

Browse files
committed
Put Client + Server behind "unstable" flag
1 parent f04d6ec commit 2d2e112

File tree

6 files changed

+44
-8
lines changed

6 files changed

+44
-8
lines changed

Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,13 @@ 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"]
1621
unstable = []
1722
hyperium_http = ["http"]
1823

src/client.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ use crate::{Request, Response, Result};
77
type BoxFuture<'a, T> = Pin<Box<dyn Future<Output = T> + 'a + Send>>;
88

99
/// An HTTP client.
10+
#[cfg(feature = "unstable")]
11+
#[cfg_attr(feature = "docs", doc(cfg(unstable)))]
1012
pub trait Client: Debug + Unpin + Send + Sync + Clone + 'static {
1113
/// Send an HTTP request from the client.
1214
fn send_req(&self, req: Request) -> BoxFuture<'static, Result<Response>>;

src/lib.rs

Lines changed: 13 additions & 5 deletions
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,29 +112,36 @@ pub mod url {
111112
};
112113
}
113114

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

117121
mod body;
118-
mod client;
119122
mod error;
120123
mod macros;
121124
mod method;
122125
mod request;
123126
mod response;
124-
mod server;
125127
mod status;
126128
mod status_code;
127129
mod type_map;
128130
mod version;
129131

132+
cfg_unstable! {
133+
mod client;
134+
mod server;
135+
136+
pub use client::Client;
137+
pub use server::Server;
138+
}
139+
130140
pub use body::Body;
131-
pub use client::Client;
132141
pub use error::{Error, Result};
133142
pub use method::Method;
134143
pub use request::Request;
135144
pub use response::Response;
136-
pub use server::Server;
137145
pub use status::Status;
138146
pub use status_code::StatusCode;
139147
pub use version::Version;

src/request.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use async_std::io::{self, BufRead, Read};
22
use async_std::sync;
33

44
use std::convert::TryInto;
5-
use std::future::Future;
65
use std::mem;
76
use std::pin::Pin;
87
use std::task::{Context, Poll};
@@ -14,9 +13,14 @@ use crate::mime::Mime;
1413
use crate::trailers::{Trailers, TrailersSender};
1514
use crate::Cookie;
1615
use crate::{Body, Method, TypeMap, Url, Version};
17-
use crate::{Client, Error, Response, Server};
1816

19-
type BoxFuture<'a, T> = Pin<Box<dyn Future<Output = T> + 'a + Send>>;
17+
cfg_unstable! {
18+
use std::future::Future;
19+
20+
use crate::{Client, Error, Response, Server};
21+
22+
type BoxFuture<'a, T> = Pin<Box<dyn Future<Output = T> + 'a + Send>>;
23+
}
2024

2125
pin_project_lite::pin_project! {
2226
/// An HTTP request.
@@ -448,13 +452,17 @@ impl Request {
448452
/// This is useful for sending a request to a server without needing to
449453
/// make any further HTTP requests. Examples include: HTTP endpoints in
450454
/// frameworks, or testing logic for requests.
455+
#[cfg(feature = "unstable")]
456+
#[cfg_attr(feature = "docs", doc(cfg(unstable)))]
451457
pub fn send_to<S: Server>(self, server: &S) -> BoxFuture<'static, Result<Response, Error>> {
452458
server.recv_req(self)
453459
}
454460

455461
/// Send a request through a client.
456462
///
457463
/// This will most likely create an HTTP request over the network.
464+
#[cfg(feature = "unstable")]
465+
#[cfg_attr(feature = "docs", doc(cfg(unstable)))]
458466
pub fn send_from<C: Client>(self, client: &C) -> BoxFuture<'static, Result<Response, Error>> {
459467
client.send_req(self)
460468
}

src/server.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ use crate::{Request, Response, Result};
77
type BoxFuture<'a, T> = Pin<Box<dyn Future<Output = T> + 'a + Send>>;
88

99
/// An HTTP server.
10+
#[cfg(feature = "unstable")]
11+
#[cfg_attr(feature = "docs", doc(cfg(unstable)))]
1012
pub trait Server: Debug + Unpin + Send + Sync + Clone + 'static {
1113
/// Receive an HTTP request on the server.
1214
fn recv_req(&self, req: Request) -> BoxFuture<'static, Result<Response>>;

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)