Use rustfmt to enforce consistent formatting
This change adds a .rustfmt.toml that includes ALL supported settings, 12 of which we have overridden to attempt to cater to our own proclivities. rustfmt is checked in the rust-nightly CI job.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
use frame::{util, Frame, Head, Error, StreamId, Kind};
|
||||
use bytes::{BufMut, Bytes, Buf};
|
||||
use bytes::{Buf, BufMut, Bytes};
|
||||
use frame::{util, Error, Frame, Head, Kind, StreamId};
|
||||
|
||||
use std::fmt;
|
||||
|
||||
@@ -92,7 +92,8 @@ impl<T> Data<T> {
|
||||
}
|
||||
|
||||
pub(crate) fn map<F, U>(self, f: F) -> Data<U>
|
||||
where F: FnOnce(T) -> U,
|
||||
where
|
||||
F: FnOnce(T) -> U,
|
||||
{
|
||||
Data {
|
||||
stream_id: self.stream_id,
|
||||
@@ -120,11 +121,11 @@ impl Data<Bytes> {
|
||||
};
|
||||
|
||||
Ok(Data {
|
||||
stream_id: head.stream_id(),
|
||||
data: payload,
|
||||
flags: flags,
|
||||
pad_len: pad_len,
|
||||
})
|
||||
stream_id: head.stream_id(),
|
||||
data: payload,
|
||||
flags: flags,
|
||||
pad_len: pad_len,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use frame::{self, Head, Error, Kind, StreamId, Reason};
|
||||
use frame::{self, Error, Head, Kind, Reason, StreamId};
|
||||
|
||||
use bytes::{BufMut, BigEndian};
|
||||
use bytes::{BigEndian, BufMut};
|
||||
|
||||
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
|
||||
pub struct GoAway {
|
||||
@@ -35,9 +35,9 @@ impl GoAway {
|
||||
let error_code = unpack_octets_4!(payload, 4, u32);
|
||||
|
||||
Ok(GoAway {
|
||||
last_stream_id: last_stream_id,
|
||||
error_code: error_code,
|
||||
})
|
||||
last_stream_id: last_stream_id,
|
||||
error_code: error_code,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn encode<B: BufMut>(&self, dst: &mut B) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use super::StreamId;
|
||||
|
||||
use bytes::{BufMut, BigEndian};
|
||||
use bytes::{BigEndian, BufMut};
|
||||
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
||||
pub struct Head {
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
use super::{StreamId, StreamDependency};
|
||||
use super::{StreamDependency, StreamId};
|
||||
use frame::{self, Error, Frame, Head, Kind};
|
||||
use hpack;
|
||||
use frame::{self, Frame, Head, Kind, Error};
|
||||
|
||||
use http::{uri, Method, StatusCode, Uri, HeaderMap};
|
||||
use http::{uri, HeaderMap, Method, StatusCode, Uri};
|
||||
use http::header::{self, HeaderName, HeaderValue};
|
||||
|
||||
use bytes::{BytesMut, Bytes};
|
||||
use byteorder::{BigEndian, ByteOrder};
|
||||
use bytes::{Bytes, BytesMut};
|
||||
use string::String;
|
||||
|
||||
use std::fmt;
|
||||
@@ -89,10 +89,7 @@ const END_STREAM: u8 = 0x1;
|
||||
const END_HEADERS: u8 = 0x4;
|
||||
const PADDED: u8 = 0x8;
|
||||
const PRIORITY: u8 = 0x20;
|
||||
const ALL: u8 = END_STREAM
|
||||
| END_HEADERS
|
||||
| PADDED
|
||||
| PRIORITY;
|
||||
const ALL: u8 = END_STREAM | END_HEADERS | PADDED | PRIORITY;
|
||||
|
||||
// ===== impl Headers =====
|
||||
|
||||
@@ -124,9 +121,7 @@ impl Headers {
|
||||
/// Loads the header frame but doesn't actually do HPACK decoding.
|
||||
///
|
||||
/// HPACK decoding is done in the `load_hpack` step.
|
||||
pub fn load(head: Head, mut src: BytesMut)
|
||||
-> Result<(Self, BytesMut), Error>
|
||||
{
|
||||
pub fn load(head: Head, mut src: BytesMut) -> Result<(Self, BytesMut), Error> {
|
||||
let flags = HeadersFlag(head.flag());
|
||||
let mut pad = 0;
|
||||
|
||||
@@ -177,11 +172,7 @@ impl Headers {
|
||||
Ok((headers, src))
|
||||
}
|
||||
|
||||
pub fn load_hpack(&mut self,
|
||||
src: BytesMut,
|
||||
decoder: &mut hpack::Decoder)
|
||||
-> Result<(), Error>
|
||||
{
|
||||
pub fn load_hpack(&mut self, src: BytesMut, decoder: &mut hpack::Decoder) -> Result<(), Error> {
|
||||
let mut reg = false;
|
||||
let mut malformed = false;
|
||||
|
||||
@@ -210,7 +201,10 @@ impl Headers {
|
||||
use hpack::Header::*;
|
||||
|
||||
match header {
|
||||
Field { name, value } => {
|
||||
Field {
|
||||
name,
|
||||
value,
|
||||
} => {
|
||||
// Connection level header fields are not supported and must
|
||||
// result in a protocol error.
|
||||
|
||||
@@ -274,9 +268,7 @@ impl Headers {
|
||||
self.fields
|
||||
}
|
||||
|
||||
pub fn encode(self, encoder: &mut hpack::Encoder, dst: &mut BytesMut)
|
||||
-> Option<Continuation>
|
||||
{
|
||||
pub fn encode(self, encoder: &mut hpack::Encoder, dst: &mut BytesMut) -> Option<Continuation> {
|
||||
let head = self.head();
|
||||
let pos = dst.len();
|
||||
|
||||
@@ -295,10 +287,10 @@ impl Headers {
|
||||
hpack::Encode::Full => None,
|
||||
hpack::Encode::Partial(state) => {
|
||||
Some(Continuation {
|
||||
stream_id: self.stream_id,
|
||||
hpack: state,
|
||||
headers: headers,
|
||||
})
|
||||
stream_id: self.stream_id,
|
||||
hpack: state,
|
||||
headers: headers,
|
||||
})
|
||||
}
|
||||
};
|
||||
|
||||
@@ -306,7 +298,7 @@ impl Headers {
|
||||
let len = (dst.len() - pos) - frame::HEADER_LEN;
|
||||
|
||||
// Write the frame length
|
||||
BigEndian::write_uint(&mut dst[pos..pos+3], len as u64, 3);
|
||||
BigEndian::write_uint(&mut dst[pos..pos + 3], len as u64, 3);
|
||||
|
||||
ret
|
||||
}
|
||||
@@ -336,9 +328,7 @@ impl fmt::Debug for Headers {
|
||||
// ===== impl PushPromise =====
|
||||
|
||||
impl PushPromise {
|
||||
pub fn load(head: Head, payload: &[u8])
|
||||
-> Result<Self, Error>
|
||||
{
|
||||
pub fn load(head: Head, payload: &[u8]) -> Result<Self, Error> {
|
||||
let flags = PushPromiseFlag(head.flag());
|
||||
|
||||
// TODO: Handle padding
|
||||
@@ -346,10 +336,10 @@ impl PushPromise {
|
||||
let (promised_id, _) = StreamId::parse(&payload[..4]);
|
||||
|
||||
Ok(PushPromise {
|
||||
stream_id: head.stream_id(),
|
||||
promised_id: promised_id,
|
||||
flags: flags,
|
||||
})
|
||||
stream_id: head.stream_id(),
|
||||
promised_id: promised_id,
|
||||
flags: flags,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn stream_id(&self) -> StreamId {
|
||||
@@ -377,7 +367,8 @@ impl Pseudo {
|
||||
unsafe { String::from_utf8_unchecked(src) }
|
||||
}
|
||||
|
||||
let path = parts.path_and_query
|
||||
let path = parts
|
||||
.path_and_query
|
||||
.map(|v| v.into())
|
||||
.unwrap_or_else(|| Bytes::from_static(b"/"));
|
||||
|
||||
@@ -456,10 +447,12 @@ impl Iterator for Iter {
|
||||
|
||||
self.pseudo = None;
|
||||
|
||||
self.fields.next()
|
||||
.map(|(name, value)| {
|
||||
Field { name: name, value: value}
|
||||
})
|
||||
self.fields.next().map(|(name, value)| {
|
||||
Field {
|
||||
name: name,
|
||||
value: value,
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ mod window_update;
|
||||
pub use self::data::Data;
|
||||
pub use self::go_away::GoAway;
|
||||
pub use self::head::{Head, Kind};
|
||||
pub use self::headers::{Headers, PushPromise, Continuation, Pseudo};
|
||||
pub use self::headers::{Continuation, Headers, Pseudo, PushPromise};
|
||||
pub use self::ping::Ping;
|
||||
pub use self::priority::{Priority, StreamDependency};
|
||||
pub use self::reason::Reason;
|
||||
@@ -52,10 +52,11 @@ pub use self::stream_id::StreamId;
|
||||
pub use self::window_update::WindowUpdate;
|
||||
|
||||
// Re-export some constants
|
||||
|
||||
pub use self::settings::{
|
||||
DEFAULT_SETTINGS_HEADER_TABLE_SIZE,
|
||||
DEFAULT_INITIAL_WINDOW_SIZE,
|
||||
DEFAULT_MAX_FRAME_SIZE,
|
||||
DEFAULT_SETTINGS_HEADER_TABLE_SIZE,
|
||||
MAX_INITIAL_WINDOW_SIZE,
|
||||
MAX_MAX_FRAME_SIZE,
|
||||
};
|
||||
@@ -74,12 +75,13 @@ pub enum Frame<T = Bytes> {
|
||||
Ping(Ping),
|
||||
GoAway(GoAway),
|
||||
WindowUpdate(WindowUpdate),
|
||||
Reset(Reset)
|
||||
Reset(Reset),
|
||||
}
|
||||
|
||||
impl<T> Frame<T> {
|
||||
pub fn map<F, U>(self, f: F) -> Frame<U>
|
||||
where F: FnOnce(T) -> U
|
||||
where
|
||||
F: FnOnce(T) -> U,
|
||||
{
|
||||
use self::Frame::*;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use bytes::{Buf, BufMut, IntoBuf};
|
||||
use frame::{Frame, Head, Kind, Error, StreamId};
|
||||
use frame::{Error, Frame, Head, Kind, StreamId};
|
||||
|
||||
const ACK_FLAG: u8 = 0x1;
|
||||
|
||||
@@ -21,7 +21,10 @@ impl Ping {
|
||||
}
|
||||
|
||||
pub fn pong(payload: Payload) -> Ping {
|
||||
Ping { ack: true, payload }
|
||||
Ping {
|
||||
ack: true,
|
||||
payload,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_ack(&self) -> bool {
|
||||
@@ -65,7 +68,10 @@ impl Ping {
|
||||
// endpoint MUST NOT respond to PING frames containing this flag.
|
||||
let ack = head.flag() & ACK_FLAG != 0;
|
||||
|
||||
Ok(Ping { ack, payload })
|
||||
Ok(Ping {
|
||||
ack,
|
||||
payload,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn encode<B: BufMut>(&self, dst: &mut B) {
|
||||
|
||||
@@ -29,9 +29,9 @@ impl Priority {
|
||||
}
|
||||
|
||||
Ok(Priority {
|
||||
stream_id: head.stream_id(),
|
||||
dependency: dependency,
|
||||
})
|
||||
stream_id: head.stream_id(),
|
||||
dependency: dependency,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,10 +63,7 @@ impl StreamDependency {
|
||||
// Read the weight
|
||||
let weight = src[4];
|
||||
|
||||
Ok(StreamDependency::new(
|
||||
dependency_id,
|
||||
weight,
|
||||
is_exclusive))
|
||||
Ok(StreamDependency::new(dependency_id, weight, is_exclusive))
|
||||
}
|
||||
|
||||
pub fn dependency_id(&self) -> StreamId {
|
||||
|
||||
@@ -37,7 +37,10 @@ impl Reason {
|
||||
RefusedStream => "refused stream before processing any application logic",
|
||||
Cancel => "stream no longer needed",
|
||||
CompressionError => "unable to maintain the header compression context",
|
||||
ConnectError => "connection established in response to a CONNECT request was reset or abnormally closed",
|
||||
ConnectError => {
|
||||
"connection established in response to a CONNECT request \
|
||||
was reset or abnormally closed"
|
||||
}
|
||||
EnhanceYourCalm => "detected excessive load generating behavior",
|
||||
InadequateSecurity => "security properties do not meet minimum requirements",
|
||||
Http11Required => "endpoint requires HTTP/1.1",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use frame::{self, Head, Error, Kind, StreamId, Reason};
|
||||
use frame::{self, Error, Head, Kind, Reason, StreamId};
|
||||
|
||||
use bytes::{BufMut, BigEndian};
|
||||
use bytes::{BigEndian, BufMut};
|
||||
|
||||
#[derive(Debug, Eq, PartialEq)]
|
||||
pub struct Reset {
|
||||
@@ -32,13 +32,15 @@ impl Reset {
|
||||
let error_code = unpack_octets_4!(payload, 0, u32);
|
||||
|
||||
Ok(Reset {
|
||||
stream_id: head.stream_id(),
|
||||
error_code: error_code,
|
||||
})
|
||||
stream_id: head.stream_id(),
|
||||
error_code: error_code,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn encode<B: BufMut>(&self, dst: &mut B) {
|
||||
trace!("encoding RESET; id={:?} code={}", self.stream_id, self.error_code);
|
||||
trace!("encoding RESET; id={:?} code={}",
|
||||
self.stream_id,
|
||||
self.error_code);
|
||||
let head = Head::new(Kind::Reset, 0, self.stream_id);
|
||||
head.encode(4, dst);
|
||||
dst.put_u32::<BigEndian>(self.error_code);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use frame::{Frame, FrameSize, Error, Head, Kind, StreamId};
|
||||
use bytes::{BytesMut, BufMut, BigEndian};
|
||||
use bytes::{BigEndian, BufMut, BytesMut};
|
||||
use frame::{Error, Frame, FrameSize, Head, Kind, StreamId};
|
||||
|
||||
#[derive(Debug, Clone, Default, Eq, PartialEq)]
|
||||
pub struct Settings {
|
||||
@@ -54,7 +54,7 @@ impl Settings {
|
||||
pub fn ack() -> Settings {
|
||||
Settings {
|
||||
flags: SettingsFlags::ack(),
|
||||
.. Settings::default()
|
||||
..Settings::default()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use frame::{self, Head, Kind, Error, StreamId};
|
||||
use frame::{self, Error, Head, Kind, StreamId};
|
||||
|
||||
use bytes::{BufMut, BigEndian};
|
||||
use bytes::{BigEndian, BufMut};
|
||||
|
||||
const SIZE_INCREMENT_MASK: u32 = 1 << 31;
|
||||
|
||||
@@ -42,9 +42,9 @@ impl WindowUpdate {
|
||||
}
|
||||
|
||||
Ok(WindowUpdate {
|
||||
stream_id: head.stream_id(),
|
||||
size_increment,
|
||||
})
|
||||
stream_id: head.stream_id(),
|
||||
size_increment,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn encode<B: BufMut>(&self, dst: &mut B) {
|
||||
|
||||
Reference in New Issue
Block a user