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:
		| @@ -6,10 +6,7 @@ use std::{error, fmt, io}; | ||||
| #[derive(Debug)] | ||||
| pub enum RecvError { | ||||
|     Connection(Reason), | ||||
|     Stream { | ||||
|         id: StreamId, | ||||
|         reason: Reason, | ||||
|     }, | ||||
|     Stream { id: StreamId, reason: Reason }, | ||||
|     Io(io::Error), | ||||
| } | ||||
|  | ||||
| @@ -56,7 +53,9 @@ impl error::Error for RecvError { | ||||
|  | ||||
|         match *self { | ||||
|             Connection(ref reason) => reason.description(), | ||||
|             Stream { ref reason, .. } => reason.description(), | ||||
|             Stream { | ||||
|                 ref reason, .. | ||||
|             } => reason.description(), | ||||
|             Io(ref e) => e.description(), | ||||
|         } | ||||
|     } | ||||
|   | ||||
| @@ -101,9 +101,9 @@ impl<T> FramedRead<T> { | ||||
|                         // treat this as a stream error (Section 5.4.2) of type | ||||
|                         // `PROTOCOL_ERROR`. | ||||
|                         return Err(Stream { | ||||
|                             id: head.stream_id(), | ||||
|                             reason: ProtocolError, | ||||
|                         }); | ||||
|                                        id: head.stream_id(), | ||||
|                                        reason: ProtocolError, | ||||
|                                    }); | ||||
|                     } | ||||
|                     _ => return Err(Connection(ProtocolError)), | ||||
|                 }; | ||||
| @@ -114,9 +114,9 @@ impl<T> FramedRead<T> { | ||||
|                         Ok(_) => {} | ||||
|                         Err(frame::Error::MalformedMessage) => { | ||||
|                             return Err(Stream { | ||||
|                                 id: head.stream_id(), | ||||
|                                 reason: ProtocolError, | ||||
|                             }); | ||||
|                                            id: head.stream_id(), | ||||
|                                            reason: ProtocolError, | ||||
|                                        }); | ||||
|                         } | ||||
|                         Err(_) => return Err(Connection(ProtocolError)), | ||||
|                     } | ||||
| @@ -125,9 +125,9 @@ impl<T> FramedRead<T> { | ||||
|                 } else { | ||||
|                     // Defer loading the frame | ||||
|                     self.partial = Some(Partial { | ||||
|                         frame: Continuable::Headers(headers), | ||||
|                         buf: payload, | ||||
|                     }); | ||||
|                                             frame: Continuable::Headers(headers), | ||||
|                                             buf: payload, | ||||
|                                         }); | ||||
|  | ||||
|                     return Ok(None); | ||||
|                 } | ||||
| @@ -157,9 +157,9 @@ impl<T> FramedRead<T> { | ||||
|                         // treat this as a stream error (Section 5.4.2) of type | ||||
|                         // `PROTOCOL_ERROR`. | ||||
|                         return Err(Stream { | ||||
|                             id: head.stream_id(), | ||||
|                             reason: ProtocolError, | ||||
|                         }); | ||||
|                                        id: head.stream_id(), | ||||
|                                        reason: ProtocolError, | ||||
|                                    }); | ||||
|                     } | ||||
|                     Err(_) => return Err(Connection(ProtocolError)), | ||||
|                 } | ||||
| @@ -192,9 +192,9 @@ impl<T> FramedRead<T> { | ||||
|                             Ok(_) => {} | ||||
|                             Err(frame::Error::MalformedMessage) => { | ||||
|                                 return Err(Stream { | ||||
|                                     id: head.stream_id(), | ||||
|                                     reason: ProtocolError, | ||||
|                                 }); | ||||
|                                                id: head.stream_id(), | ||||
|                                                reason: ProtocolError, | ||||
|                                            }); | ||||
|                             } | ||||
|                             Err(_) => return Err(Connection(ProtocolError)), | ||||
|                         } | ||||
| @@ -234,7 +234,8 @@ impl<T> FramedRead<T> { | ||||
| } | ||||
|  | ||||
| impl<T> Stream for FramedRead<T> | ||||
|     where T: AsyncRead, | ||||
| where | ||||
|     T: AsyncRead, | ||||
| { | ||||
|     type Item = Frame; | ||||
|     type Error = RecvError; | ||||
| @@ -248,7 +249,7 @@ impl<T> Stream for FramedRead<T> | ||||
|             }; | ||||
|  | ||||
|             trace!("poll; bytes={}B", bytes.len()); | ||||
|             if let Some(frame) = try!(self.decode_frame(bytes)) { | ||||
|             if let Some(frame) = self.decode_frame(bytes)? { | ||||
|                 debug!("received; frame={:?}", frame); | ||||
|                 return Ok(Async::Ready(Some(frame))); | ||||
|             } | ||||
|   | ||||
| @@ -3,9 +3,9 @@ use codec::UserError::*; | ||||
| use frame::{self, Frame, FrameSize}; | ||||
| use hpack; | ||||
|  | ||||
| use bytes::{Buf, BufMut, BytesMut}; | ||||
| use futures::*; | ||||
| use tokio_io::{AsyncRead, AsyncWrite}; | ||||
| use bytes::{BytesMut, Buf, BufMut}; | ||||
|  | ||||
| use std::io::{self, Cursor}; | ||||
|  | ||||
| @@ -51,8 +51,9 @@ const CHAIN_THRESHOLD: usize = 256; | ||||
|  | ||||
| // TODO: Make generic | ||||
| impl<T, B> FramedWrite<T, B> | ||||
|     where T: AsyncWrite, | ||||
|           B: Buf, | ||||
| where | ||||
|     T: AsyncWrite, | ||||
|     B: Buf, | ||||
| { | ||||
|     pub fn new(inner: T) -> FramedWrite<T, B> { | ||||
|         FramedWrite { | ||||
| @@ -72,7 +73,7 @@ impl<T, B> FramedWrite<T, B> | ||||
|     pub fn poll_ready(&mut self) -> Poll<(), io::Error> { | ||||
|         if !self.has_capacity() { | ||||
|             // Try flushing | ||||
|             try!(self.flush()); | ||||
|             self.flush()?; | ||||
|  | ||||
|             if !self.has_capacity() { | ||||
|                 return Ok(Async::NotReady); | ||||
| @@ -248,7 +249,8 @@ impl<T: io::Read, B> io::Read for FramedWrite<T, B> { | ||||
|  | ||||
| impl<T: AsyncRead, B> AsyncRead for FramedWrite<T, B> { | ||||
|     fn read_buf<B2: BufMut>(&mut self, buf: &mut B2) -> Poll<usize, io::Error> | ||||
|         where Self: Sized, | ||||
|     where | ||||
|         Self: Sized, | ||||
|     { | ||||
|         self.inner.read_buf(buf) | ||||
|     } | ||||
|   | ||||
| @@ -2,12 +2,12 @@ mod error; | ||||
| mod framed_read; | ||||
| mod framed_write; | ||||
|  | ||||
| pub use self::error::{SendError, RecvError, UserError}; | ||||
| pub use self::error::{RecvError, SendError, UserError}; | ||||
|  | ||||
| use self::framed_read::FramedRead; | ||||
| use self::framed_write::FramedWrite; | ||||
|  | ||||
| use frame::{self, Frame, Data}; | ||||
| use frame::{self, Data, Frame}; | ||||
|  | ||||
| use futures::*; | ||||
|  | ||||
| @@ -24,16 +24,14 @@ pub struct Codec<T, B> { | ||||
| } | ||||
|  | ||||
| impl<T, B> Codec<T, B> | ||||
|     where T: AsyncRead + AsyncWrite, | ||||
|           B: Buf, | ||||
| where | ||||
|     T: AsyncRead + AsyncWrite, | ||||
|     B: Buf, | ||||
| { | ||||
|     /// Returns a new `Codec` with the default max frame size | ||||
|     #[inline] | ||||
|     pub fn new(io: T) -> Self { | ||||
|         Self::with_max_recv_frame_size( | ||||
|             io, | ||||
|             frame::DEFAULT_MAX_FRAME_SIZE as usize | ||||
|         ) | ||||
|         Self::with_max_recv_frame_size(io, frame::DEFAULT_MAX_FRAME_SIZE as usize) | ||||
|     } | ||||
|  | ||||
|     /// Returns a new `Codec` with the given maximum frame size | ||||
| @@ -52,12 +50,13 @@ impl<T, B> Codec<T, B> | ||||
|  | ||||
|         let inner = FramedRead::new(delimited); | ||||
|  | ||||
|         Codec { inner } | ||||
|         Codec { | ||||
|             inner, | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl<T, B> Codec<T, B> { | ||||
|  | ||||
|     /// Updates the max received frame size. | ||||
|     /// | ||||
|     /// The change takes effect the next time a frame is decoded. In other | ||||
| @@ -68,7 +67,6 @@ impl<T, B> Codec<T, B> { | ||||
|     pub fn set_max_recv_frame_size(&mut self, val: usize) { | ||||
|         // TODO: should probably make some assertions about max frame size... | ||||
|         self.inner.set_max_frame_size(val) | ||||
|  | ||||
|     } | ||||
|  | ||||
|     /// Returns the current max received frame size setting. | ||||
| @@ -112,8 +110,9 @@ impl<T, B> Codec<T, B> { | ||||
| } | ||||
|  | ||||
| impl<T, B> Codec<T, B> | ||||
|     where T: AsyncWrite, | ||||
|           B: Buf, | ||||
| where | ||||
|     T: AsyncWrite, | ||||
|     B: Buf, | ||||
| { | ||||
|     /// Returns `Ready` when the codec can buffer a frame | ||||
|     pub fn poll_ready(&mut self) -> Poll<(), io::Error> { | ||||
| @@ -126,8 +125,7 @@ impl<T, B> Codec<T, B> | ||||
|     /// accepted. | ||||
|     /// | ||||
|     /// TODO: Rename this to avoid conflicts with Sink::buffer | ||||
|     pub fn buffer(&mut self, item: Frame<B>) -> Result<(), UserError> | ||||
|     { | ||||
|     pub fn buffer(&mut self, item: Frame<B>) -> Result<(), UserError> { | ||||
|         self.framed_write().buffer(item) | ||||
|     } | ||||
|  | ||||
| @@ -143,7 +141,8 @@ impl<T, B> Codec<T, B> | ||||
| } | ||||
|  | ||||
| impl<T, B> Stream for Codec<T, B> | ||||
|     where T: AsyncRead, | ||||
| where | ||||
|     T: AsyncRead, | ||||
| { | ||||
|     type Item = Frame; | ||||
|     type Error = RecvError; | ||||
| @@ -154,8 +153,9 @@ impl<T, B> Stream for Codec<T, B> | ||||
| } | ||||
|  | ||||
| impl<T, B> Sink for Codec<T, B> | ||||
|     where T: AsyncWrite, | ||||
|           B: Buf, | ||||
| where | ||||
|     T: AsyncWrite, | ||||
|     B: Buf, | ||||
| { | ||||
|     type SinkItem = Frame<B>; | ||||
|     type SinkError = SendError; | ||||
| @@ -182,7 +182,8 @@ impl<T, B> Sink for Codec<T, B> | ||||
|  | ||||
| // TODO: remove (or improve) this | ||||
| impl<T> From<T> for Codec<T, ::std::io::Cursor<::bytes::Bytes>> | ||||
|     where T: AsyncRead + AsyncWrite, | ||||
| where | ||||
|     T: AsyncRead + AsyncWrite, | ||||
| { | ||||
|     fn from(src: T) -> Self { | ||||
|         Self::new(src) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user