Add must_use to futures, deny missing docs (#171)

This commit is contained in:
Sean McArthur
2017-10-27 14:08:16 -07:00
committed by Carl Lerche
parent 24a796da72
commit b1d282799b
5 changed files with 62 additions and 3 deletions

View File

@@ -1,3 +1,4 @@
//! HTTP2 client side.
use {SendStream, RecvStream, ReleaseCapacity}; use {SendStream, RecvStream, ReleaseCapacity};
use codec::{Codec, RecvError}; use codec::{Codec, RecvError};
use frame::{Headers, Pseudo, Reason, Settings, StreamId}; use frame::{Headers, Pseudo, Reason, Settings, StreamId};
@@ -14,6 +15,7 @@ use std::io;
use std::marker::PhantomData; use std::marker::PhantomData;
/// In progress H2 connection binding /// In progress H2 connection binding
#[must_use = "futures do nothing unless polled"]
pub struct Handshake<T: AsyncRead + AsyncWrite, B: IntoBuf = Bytes> { pub struct Handshake<T: AsyncRead + AsyncWrite, B: IntoBuf = Bytes> {
builder: Builder, builder: Builder,
inner: MapErr<WriteAll<T, &'static [u8]>, fn(io::Error) -> ::Error>, inner: MapErr<WriteAll<T, &'static [u8]>, fn(io::Error) -> ::Error>,
@@ -26,11 +28,17 @@ pub struct Client<B: IntoBuf> {
pending: Option<proto::StreamKey>, pending: Option<proto::StreamKey>,
} }
/// A future to drive the H2 protocol on a connection.
///
/// This must be placed in an executor to ensure proper connection management.
#[must_use = "futures do nothing unless polled"]
pub struct Connection<T, B: IntoBuf> { pub struct Connection<T, B: IntoBuf> {
inner: proto::Connection<T, Peer, B>, inner: proto::Connection<T, Peer, B>,
} }
/// A future of an HTTP response.
#[derive(Debug)] #[derive(Debug)]
#[must_use = "futures do nothing unless polled"]
pub struct ResponseFuture { pub struct ResponseFuture {
inner: proto::OpaqueStreamRef, inner: proto::OpaqueStreamRef,
} }

View File

@@ -1,25 +1,56 @@
use std::fmt; use std::fmt;
/// HTTP2 Error codes
///
/// See [Error Codes in the spec][spec].
///
/// [spec}: http://httpwg.org/specs/rfc7540.html#ErrorCodes
#[derive(PartialEq, Eq, Clone, Copy)] #[derive(PartialEq, Eq, Clone, Copy)]
pub struct Reason(u32); pub struct Reason(u32);
impl Reason { impl Reason {
/// The associated condition is not a result of an error.
///
/// For example, a GOAWAY might include this code to indicate graceful
/// shutdown of a connection.
pub const NO_ERROR: Reason = Reason(0); pub const NO_ERROR: Reason = Reason(0);
/// The endpoint detected an unspecific protocol error.
///
/// This error is for use when a more specific error code is not available.
pub const PROTOCOL_ERROR: Reason = Reason(1); pub const PROTOCOL_ERROR: Reason = Reason(1);
/// The endpoint encountered an unexpected internal error.
pub const INTERNAL_ERROR: Reason = Reason(2); pub const INTERNAL_ERROR: Reason = Reason(2);
/// The endpoint detected that its peer violated the flow-control protocol.
pub const FLOW_CONTROL_ERROR: Reason = Reason(3); pub const FLOW_CONTROL_ERROR: Reason = Reason(3);
/// The endpoint sent a SETTINGS frame but did not receive a response in
/// a timely manner.
pub const SETTINGS_TIMEOUT: Reason = Reason(4); pub const SETTINGS_TIMEOUT: Reason = Reason(4);
/// The endpoint received a frame after a stream was half-closed.
pub const STREAM_CLOSED: Reason = Reason(5); pub const STREAM_CLOSED: Reason = Reason(5);
/// The endpoint received a frame with an invalid size.
pub const FRAME_SIZE_ERROR: Reason = Reason(6); pub const FRAME_SIZE_ERROR: Reason = Reason(6);
/// The endpoint refused the stream prior to performing any application
/// processing.
pub const REFUSED_STREAM: Reason = Reason(7); pub const REFUSED_STREAM: Reason = Reason(7);
/// Used by the endpoint to indicate that the stream is no longer needed.
pub const CANCEL: Reason = Reason(8); pub const CANCEL: Reason = Reason(8);
/// The endpoint is unable to maintain the header compression context for
/// the connection.
pub const COMPRESSION_ERROR: Reason = Reason(9); pub const COMPRESSION_ERROR: Reason = Reason(9);
/// The connection established in response to a CONNECT request was reset
/// or abnormally closed.
pub const CONNECT_ERROR: Reason = Reason(10); pub const CONNECT_ERROR: Reason = Reason(10);
/// The endpoint detected that its peer is exhibiting a behavior that might
/// be generating excessive load.
pub const ENHANCE_YOUR_CALM: Reason = Reason(11); pub const ENHANCE_YOUR_CALM: Reason = Reason(11);
/// The underlying transport has properties that do not meet minimum
/// security requirements.
pub const INADEQUATE_SECURITY: Reason = Reason(12); pub const INADEQUATE_SECURITY: Reason = Reason(12);
pub const HTTP11_REQUIRED: Reason = Reason(13); /// The endpoint requires that HTTP/1.1 be used instead of HTTP/2.
pub const HTTP_1_1_REQUIRED: Reason = Reason(13);
/// Get a string description of the error code.
pub fn description(&self) -> &str { pub fn description(&self) -> &str {
match self.0 { match self.0 {
0 => "not a result of an error", 0 => "not a result of an error",

View File

@@ -1,4 +1,6 @@
#![deny(warnings, missing_debug_implementations)] #![deny(warnings, missing_debug_implementations, missing_docs)]
//! HTTP2
#[macro_use] #[macro_use]
extern crate futures; extern crate futures;
@@ -24,6 +26,7 @@ extern crate string;
extern crate ordermap; extern crate ordermap;
mod error; mod error;
#[cfg_attr(feature = "unstable", allow(missing_docs))]
mod codec; mod codec;
mod hpack; mod hpack;
mod proto; mod proto;
@@ -32,6 +35,7 @@ mod proto;
mod frame; mod frame;
#[cfg(feature = "unstable")] #[cfg(feature = "unstable")]
#[allow(missing_docs)]
pub mod frame; pub mod frame;
pub mod client; pub mod client;

View File

@@ -1,3 +1,5 @@
//! HTTP2 server side.
use {SendStream, RecvStream, ReleaseCapacity}; use {SendStream, RecvStream, ReleaseCapacity};
use codec::{Codec, RecvError}; use codec::{Codec, RecvError};
use frame::{self, Reason, Settings, StreamId}; use frame::{self, Reason, Settings, StreamId};
@@ -10,6 +12,7 @@ use tokio_io::{AsyncRead, AsyncWrite};
use std::{convert, fmt, mem}; use std::{convert, fmt, mem};
/// In progress H2 connection binding /// In progress H2 connection binding
#[must_use = "futures do nothing unless polled"]
pub struct Handshake<T: AsyncRead + AsyncWrite, B: IntoBuf = Bytes> { pub struct Handshake<T: AsyncRead + AsyncWrite, B: IntoBuf = Bytes> {
/// SETTINGS frame that will be sent once the connection is established. /// SETTINGS frame that will be sent once the connection is established.
settings: Settings, settings: Settings,
@@ -18,6 +21,7 @@ pub struct Handshake<T: AsyncRead + AsyncWrite, B: IntoBuf = Bytes> {
} }
/// Marker type indicating a client peer /// Marker type indicating a client peer
#[must_use = "streams do nothing unless polled"]
pub struct Server<T, B: IntoBuf> { pub struct Server<T, B: IntoBuf> {
connection: Connection<T, Peer, B>, connection: Connection<T, Peer, B>,
} }
@@ -31,7 +35,7 @@ pub struct Builder {
/// Respond to a request /// Respond to a request
/// ///
/// ///
/// Instances of `Respond` are used to send a respond or reserve push promises. /// Instances of `Respond` are used to send a response or reserve push promises.
#[derive(Debug)] #[derive(Debug)]
pub struct Respond<B: IntoBuf> { pub struct Respond<B: IntoBuf> {
inner: proto::StreamRef<B::Buf>, inner: proto::StreamRef<B::Buf>,

View File

@@ -1,3 +1,4 @@
use codec::UserError;
use frame::Reason; use frame::Reason;
use proto::{self, WindowSize}; use proto::{self, WindowSize};
@@ -7,15 +8,19 @@ use http::{HeaderMap};
use std::fmt; use std::fmt;
/// Send frames to a remote.
#[derive(Debug)] #[derive(Debug)]
pub struct SendStream<B: IntoBuf> { pub struct SendStream<B: IntoBuf> {
inner: proto::StreamRef<B::Buf>, inner: proto::StreamRef<B::Buf>,
} }
/// Receive frames from a remote.
#[must_use = "streams do nothing unless polled"]
pub struct RecvStream { pub struct RecvStream {
inner: ReleaseCapacity, inner: ReleaseCapacity,
} }
/// A handle to release window capacity to a remote stream.
#[derive(Debug)] #[derive(Debug)]
pub struct ReleaseCapacity { pub struct ReleaseCapacity {
inner: proto::OpaqueStreamRef, inner: proto::OpaqueStreamRef,
@@ -85,6 +90,9 @@ impl RecvStream {
self.inner.inner.is_end_stream() self.inner.inner.is_end_stream()
} }
/// Get a mutable reference to this streams `ReleaseCapacity`.
///
/// It can be used immediately, or cloned to be used later.
pub fn release_capacity(&mut self) -> &mut ReleaseCapacity { pub fn release_capacity(&mut self) -> &mut ReleaseCapacity {
&mut self.inner &mut self.inner
} }
@@ -121,7 +129,11 @@ impl ReleaseCapacity {
ReleaseCapacity { inner } ReleaseCapacity { inner }
} }
/// Release window capacity back to remote stream.
pub fn release_capacity(&mut self, sz: usize) -> Result<(), ::Error> { pub fn release_capacity(&mut self, sz: usize) -> Result<(), ::Error> {
if sz > proto::MAX_WINDOW_SIZE as usize {
return Err(UserError::ReleaseCapacityTooBig.into());
}
self.inner self.inner
.release_capacity(sz as proto::WindowSize) .release_capacity(sz as proto::WindowSize)
.map_err(Into::into) .map_err(Into::into)