1
0
mirror of https://github.com/actix/actix-extras.git synced 2024-11-28 09:42:40 +01:00

clippy warnings

This commit is contained in:
Nikolay Kim 2018-10-29 16:39:46 -07:00
parent 540ad18432
commit c2540cc59b
13 changed files with 76 additions and 48 deletions

View File

@ -536,7 +536,8 @@ impl ClientRequestBuilder {
#[inline] #[inline]
fn parts<'a>( fn parts<'a>(
parts: &'a mut Option<ClientRequest>, err: &Option<HttpError>, parts: &'a mut Option<ClientRequest>,
err: &Option<HttpError>,
) -> Option<&'a mut ClientRequest> { ) -> Option<&'a mut ClientRequest> {
if err.is_some() { if err.is_some() {
return None; return None;

View File

@ -66,7 +66,9 @@ impl Default for ServiceConfig {
impl ServiceConfig { impl ServiceConfig {
/// Create instance of `ServiceConfig` /// Create instance of `ServiceConfig`
pub(crate) fn new( pub(crate) fn new(
keep_alive: KeepAlive, client_timeout: u64, client_disconnect: u64, keep_alive: KeepAlive,
client_timeout: u64,
client_disconnect: u64,
) -> ServiceConfig { ) -> ServiceConfig {
let (keep_alive, ka_enabled) = match keep_alive { let (keep_alive, ka_enabled) = match keep_alive {
KeepAlive::Timeout(val) => (val as u64, true), KeepAlive::Timeout(val) => (val as u64, true),

View File

@ -102,7 +102,9 @@ impl ClientCodec {
} }
fn encode_response( fn encode_response(
&mut self, msg: ClientRequest, buffer: &mut BytesMut, &mut self,
msg: ClientRequest,
buffer: &mut BytesMut,
) -> io::Result<()> { ) -> io::Result<()> {
// Connection upgrade // Connection upgrade
if msg.upgrade() { if msg.upgrade() {
@ -187,7 +189,9 @@ impl Encoder for ClientCodec {
type Error = io::Error; type Error = io::Error;
fn encode( fn encode(
&mut self, item: Self::Item, dst: &mut BytesMut, &mut self,
item: Self::Item,
dst: &mut BytesMut,
) -> Result<(), Self::Error> { ) -> Result<(), Self::Error> {
match item { match item {
Message::Item(res) => { Message::Item(res) => {

View File

@ -103,7 +103,9 @@ impl Codec {
} }
fn encode_response( fn encode_response(
&mut self, mut msg: Response, buffer: &mut BytesMut, &mut self,
mut msg: Response,
buffer: &mut BytesMut,
) -> io::Result<()> { ) -> io::Result<()> {
let ka = self.flags.contains(Flags::KEEPALIVE_ENABLED) && msg let ka = self.flags.contains(Flags::KEEPALIVE_ENABLED) && msg
.keep_alive() .keep_alive()
@ -277,7 +279,9 @@ impl Encoder for Codec {
type Error = io::Error; type Error = io::Error;
fn encode( fn encode(
&mut self, item: Self::Item, dst: &mut BytesMut, &mut self,
item: Self::Item,
dst: &mut BytesMut,
) -> Result<(), Self::Error> { ) -> Result<(), Self::Error> {
match item { match item {
Message::Item(res) => { Message::Item(res) => {

View File

@ -334,7 +334,9 @@ pub(crate) struct HeaderIndex {
impl HeaderIndex { impl HeaderIndex {
pub(crate) fn record( pub(crate) fn record(
bytes: &[u8], headers: &[httparse::Header], indices: &mut [HeaderIndex], bytes: &[u8],
headers: &[httparse::Header],
indices: &mut [HeaderIndex],
) { ) {
let bytes_ptr = bytes.as_ptr() as usize; let bytes_ptr = bytes.as_ptr() as usize;
for (header, indices) in headers.iter().zip(indices.iter_mut()) { for (header, indices) in headers.iter().zip(indices.iter_mut()) {
@ -491,7 +493,10 @@ macro_rules! byte (
impl ChunkedState { impl ChunkedState {
fn step( fn step(
&self, body: &mut BytesMut, size: &mut u64, buf: &mut Option<Bytes>, &self,
body: &mut BytesMut,
size: &mut u64,
buf: &mut Option<Bytes>,
) -> Poll<ChunkedState, io::Error> { ) -> Poll<ChunkedState, io::Error> {
use self::ChunkedState::*; use self::ChunkedState::*;
match *self { match *self {
@ -554,7 +559,8 @@ impl ChunkedState {
} }
} }
fn read_size_lf( fn read_size_lf(
rdr: &mut BytesMut, size: &mut u64, rdr: &mut BytesMut,
size: &mut u64,
) -> Poll<ChunkedState, io::Error> { ) -> Poll<ChunkedState, io::Error> {
match byte!(rdr) { match byte!(rdr) {
b'\n' if *size > 0 => Ok(Async::Ready(ChunkedState::Body)), b'\n' if *size > 0 => Ok(Async::Ready(ChunkedState::Body)),
@ -567,7 +573,9 @@ impl ChunkedState {
} }
fn read_body( fn read_body(
rdr: &mut BytesMut, rem: &mut u64, buf: &mut Option<Bytes>, rdr: &mut BytesMut,
rem: &mut u64,
buf: &mut Option<Bytes>,
) -> Poll<ChunkedState, io::Error> { ) -> Poll<ChunkedState, io::Error> {
trace!("Chunked read, remaining={:?}", rem); trace!("Chunked read, remaining={:?}", rem);

View File

@ -90,7 +90,10 @@ where
/// Create http/1 dispatcher with slow request timeout. /// Create http/1 dispatcher with slow request timeout.
pub fn with_timeout( pub fn with_timeout(
stream: T, config: ServiceConfig, timeout: Option<Delay>, service: S, stream: T,
config: ServiceConfig,
timeout: Option<Delay>,
service: S,
) -> Self { ) -> Self {
let keepalive = config.keep_alive_enabled(); let keepalive = config.keep_alive_enabled();
let flags = if keepalive { let flags = if keepalive {
@ -173,19 +176,15 @@ where
// process // process
loop { loop {
let state = match self.state { let state = match self.state {
State::None => loop { State::None => if let Some(msg) = self.messages.pop_front() {
break if let Some(msg) = self.messages.pop_front() { match msg {
match msg { DispatcherMessage::Item(req) => Some(self.handle_request(req)?),
DispatcherMessage::Item(req) => { DispatcherMessage::Error(res) => Some(State::SendResponse(
Some(self.handle_request(req)?) Some((Message::Item(res), Body::Empty)),
} )),
DispatcherMessage::Error(res) => Some(State::SendResponse( }
Some((Message::Item(res), Body::Empty)), } else {
)), None
}
} else {
None
};
}, },
// call inner service // call inner service
State::ServiceCall(ref mut fut) => { State::ServiceCall(ref mut fut) => {
@ -255,7 +254,7 @@ where
.framed .framed
.as_mut() .as_mut()
.unwrap() .unwrap()
.start_send(Message::Chunk(Some(item.into()))) .start_send(Message::Chunk(Some(item)))
{ {
Ok(AsyncSink::Ready) => { Ok(AsyncSink::Ready) => {
self.flags.remove(Flags::FLUSHED); self.flags.remove(Flags::FLUSHED);
@ -299,7 +298,8 @@ where
} }
fn handle_request( fn handle_request(
&mut self, req: Request, &mut self,
req: Request,
) -> Result<State<S>, DispatchError<S::Error>> { ) -> Result<State<S>, DispatchError<S::Error>> {
let mut task = self.service.call(req); let mut task = self.service.call(req);
match task.poll().map_err(DispatchError::Service)? { match task.poll().map_err(DispatchError::Service)? {
@ -324,7 +324,7 @@ where
} }
let mut updated = false; let mut updated = false;
'outer: loop { loop {
match self.framed.as_mut().unwrap().poll() { match self.framed.as_mut().unwrap().poll() {
Ok(Async::Ready(Some(msg))) => { Ok(Async::Ready(Some(msg))) => {
updated = true; updated = true;

View File

@ -107,7 +107,9 @@ impl ResponseEncoder {
} }
fn streaming_encoding( fn streaming_encoding(
&mut self, version: Version, resp: &mut Response, &mut self,
version: Version,
resp: &mut Response,
) -> TransferEncoding { ) -> TransferEncoding {
match resp.chunked() { match resp.chunked() {
Some(true) => { Some(true) => {

View File

@ -253,7 +253,7 @@ where
type Future = Dispatcher<T, S>; type Future = Dispatcher<T, S>;
fn poll_ready(&mut self) -> Poll<(), Self::Error> { fn poll_ready(&mut self) -> Poll<(), Self::Error> {
self.srv.poll_ready().map_err(|e| DispatchError::Service(e)) self.srv.poll_ready().map_err(DispatchError::Service)
} }
fn call(&mut self, req: Self::Request) -> Self::Future { fn call(&mut self, req: Self::Request) -> Self::Future {

View File

@ -690,9 +690,10 @@ impl ResponseBuilder {
} }
#[inline] #[inline]
#[cfg_attr(feature = "cargo-clippy", allow(clippy::borrowed_box))] #[cfg_attr(feature = "cargo-clippy", allow(borrowed_box))]
fn parts<'a>( fn parts<'a>(
parts: &'a mut Option<Box<InnerResponse>>, err: &Option<HttpError>, parts: &'a mut Option<Box<InnerResponse>>,
err: &Option<HttpError>,
) -> Option<&'a mut Box<InnerResponse>> { ) -> Option<&'a mut Box<InnerResponse>> {
if err.is_some() { if err.is_some() {
return None; return None;
@ -871,7 +872,8 @@ impl ResponsePool {
#[inline] #[inline]
pub fn get_builder( pub fn get_builder(
pool: &'static ResponsePool, status: StatusCode, pool: &'static ResponsePool,
status: StatusCode,
) -> ResponseBuilder { ) -> ResponseBuilder {
if let Some(mut msg) = pool.0.borrow_mut().pop_front() { if let Some(mut msg) = pool.0.borrow_mut().pop_front() {
msg.status = status; msg.status = status;
@ -894,7 +896,9 @@ impl ResponsePool {
#[inline] #[inline]
pub fn get_response( pub fn get_response(
pool: &'static ResponsePool, status: StatusCode, body: Body, pool: &'static ResponsePool,
status: StatusCode,
body: Body,
) -> Response { ) -> Response {
if let Some(mut msg) = pool.0.borrow_mut().pop_front() { if let Some(mut msg) = pool.0.borrow_mut().pop_front() {
msg.status = status; msg.status = status;

View File

@ -97,12 +97,10 @@ where
} }
match self.framed.as_mut().unwrap().poll_complete() { match self.framed.as_mut().unwrap().poll_complete() {
Ok(Async::Ready(_)) => { Ok(Async::Ready(_)) => {
return Err((self.err.take().unwrap(), self.framed.take().unwrap())) Err((self.err.take().unwrap(), self.framed.take().unwrap()))
} }
Ok(Async::NotReady) => Ok(Async::NotReady), Ok(Async::NotReady) => Ok(Async::NotReady),
Err(_) => { Err(_) => Err((self.err.take().unwrap(), self.framed.take().unwrap())),
return Err((self.err.take().unwrap(), self.framed.take().unwrap()))
}
} }
} }
} }

View File

@ -137,13 +137,13 @@ where
let fut = Box::new( let fut = Box::new(
self.connector self.connector
.call(connect) .call(connect)
.map_err(|e| ClientError::from(e)) .map_err(ClientError::from)
.and_then(move |io| { .and_then(move |io| {
// h1 protocol // h1 protocol
let framed = Framed::new(io, h1::ClientCodec::default()); let framed = Framed::new(io, h1::ClientCodec::default());
framed framed
.send(request.into()) .send(request.into())
.map_err(|e| ClientError::from(e)) .map_err(ClientError::from)
.and_then(|framed| { .and_then(|framed| {
framed framed
.into_future() .into_future()

View File

@ -13,7 +13,9 @@ pub struct Parser;
impl Parser { impl Parser {
fn parse_metadata( fn parse_metadata(
src: &[u8], server: bool, max_size: usize, src: &[u8],
server: bool,
max_size: usize,
) -> Result<Option<(usize, bool, OpCode, usize, Option<u32>)>, ProtocolError> { ) -> Result<Option<(usize, bool, OpCode, usize, Option<u32>)>, ProtocolError> {
let chunk_len = src.len(); let chunk_len = src.len();
@ -86,7 +88,9 @@ impl Parser {
/// Parse the input stream into a frame. /// Parse the input stream into a frame.
pub fn parse( pub fn parse(
src: &mut BytesMut, server: bool, max_size: usize, src: &mut BytesMut,
server: bool,
max_size: usize,
) -> Result<Option<(bool, OpCode, Option<BytesMut>)>, ProtocolError> { ) -> Result<Option<(bool, OpCode, Option<BytesMut>)>, ProtocolError> {
// try to parse ws frame metadata // try to parse ws frame metadata
let (idx, finished, opcode, length, mask) = let (idx, finished, opcode, length, mask) =
@ -148,7 +152,11 @@ impl Parser {
/// Generate binary representation /// Generate binary representation
pub fn write_message<B: Into<Binary>>( pub fn write_message<B: Into<Binary>>(
dst: &mut BytesMut, pl: B, op: OpCode, fin: bool, mask: bool, dst: &mut BytesMut,
pl: B,
op: OpCode,
fin: bool,
mask: bool,
) { ) {
let payload = pl.into(); let payload = pl.into();
let one: u8 = if fin { let one: u8 = if fin {

View File

@ -1,5 +1,5 @@
//! This is code from [Tungstenite project](https://github.com/snapview/tungstenite-rs) //! This is code from [Tungstenite project](https://github.com/snapview/tungstenite-rs)
#![cfg_attr(feature = "cargo-clippy", allow(clippy::cast_ptr_alignment))] #![cfg_attr(feature = "cargo-clippy", allow(cast_ptr_alignment))]
use std::ptr::copy_nonoverlapping; use std::ptr::copy_nonoverlapping;
use std::slice; use std::slice;
@ -19,7 +19,7 @@ impl<'a> ShortSlice<'a> {
/// Faster version of `apply_mask()` which operates on 8-byte blocks. /// Faster version of `apply_mask()` which operates on 8-byte blocks.
#[inline] #[inline]
#[cfg_attr(feature = "cargo-clippy", allow(clippy::cast_lossless))] #[cfg_attr(feature = "cargo-clippy", allow(cast_lossless))]
pub(crate) fn apply_mask(buf: &mut [u8], mask_u32: u32) { pub(crate) fn apply_mask(buf: &mut [u8], mask_u32: u32) {
// Extend the mask to 64 bits // Extend the mask to 64 bits
let mut mask_u64 = ((mask_u32 as u64) << 32) | (mask_u32 as u64); let mut mask_u64 = ((mask_u32 as u64) << 32) | (mask_u32 as u64);
@ -50,10 +50,7 @@ pub(crate) fn apply_mask(buf: &mut [u8], mask_u32: u32) {
// TODO: copy_nonoverlapping here compiles to call memcpy. While it is not so // TODO: copy_nonoverlapping here compiles to call memcpy. While it is not so
// inefficient, it could be done better. The compiler does not understand that // inefficient, it could be done better. The compiler does not understand that
// a `ShortSlice` must be smaller than a u64. // a `ShortSlice` must be smaller than a u64.
#[cfg_attr( #[cfg_attr(feature = "cargo-clippy", allow(needless_pass_by_value))]
feature = "cargo-clippy",
allow(clippy::needless_pass_by_value)
)]
fn xor_short(buf: ShortSlice, mask: u64) { fn xor_short(buf: ShortSlice, mask: u64) {
// Unsafe: we know that a `ShortSlice` fits in a u64 // Unsafe: we know that a `ShortSlice` fits in a u64
unsafe { unsafe {