mirror of
https://github.com/actix/actix-extras.git
synced 2024-11-24 16:02:59 +01:00
clippy warnings
This commit is contained in:
parent
540ad18432
commit
c2540cc59b
@ -536,7 +536,8 @@ impl ClientRequestBuilder {
|
||||
|
||||
#[inline]
|
||||
fn parts<'a>(
|
||||
parts: &'a mut Option<ClientRequest>, err: &Option<HttpError>,
|
||||
parts: &'a mut Option<ClientRequest>,
|
||||
err: &Option<HttpError>,
|
||||
) -> Option<&'a mut ClientRequest> {
|
||||
if err.is_some() {
|
||||
return None;
|
||||
|
@ -66,7 +66,9 @@ impl Default for ServiceConfig {
|
||||
impl ServiceConfig {
|
||||
/// Create instance of `ServiceConfig`
|
||||
pub(crate) fn new(
|
||||
keep_alive: KeepAlive, client_timeout: u64, client_disconnect: u64,
|
||||
keep_alive: KeepAlive,
|
||||
client_timeout: u64,
|
||||
client_disconnect: u64,
|
||||
) -> ServiceConfig {
|
||||
let (keep_alive, ka_enabled) = match keep_alive {
|
||||
KeepAlive::Timeout(val) => (val as u64, true),
|
||||
|
@ -102,7 +102,9 @@ impl ClientCodec {
|
||||
}
|
||||
|
||||
fn encode_response(
|
||||
&mut self, msg: ClientRequest, buffer: &mut BytesMut,
|
||||
&mut self,
|
||||
msg: ClientRequest,
|
||||
buffer: &mut BytesMut,
|
||||
) -> io::Result<()> {
|
||||
// Connection upgrade
|
||||
if msg.upgrade() {
|
||||
@ -187,7 +189,9 @@ impl Encoder for ClientCodec {
|
||||
type Error = io::Error;
|
||||
|
||||
fn encode(
|
||||
&mut self, item: Self::Item, dst: &mut BytesMut,
|
||||
&mut self,
|
||||
item: Self::Item,
|
||||
dst: &mut BytesMut,
|
||||
) -> Result<(), Self::Error> {
|
||||
match item {
|
||||
Message::Item(res) => {
|
||||
|
@ -103,7 +103,9 @@ impl Codec {
|
||||
}
|
||||
|
||||
fn encode_response(
|
||||
&mut self, mut msg: Response, buffer: &mut BytesMut,
|
||||
&mut self,
|
||||
mut msg: Response,
|
||||
buffer: &mut BytesMut,
|
||||
) -> io::Result<()> {
|
||||
let ka = self.flags.contains(Flags::KEEPALIVE_ENABLED) && msg
|
||||
.keep_alive()
|
||||
@ -277,7 +279,9 @@ impl Encoder for Codec {
|
||||
type Error = io::Error;
|
||||
|
||||
fn encode(
|
||||
&mut self, item: Self::Item, dst: &mut BytesMut,
|
||||
&mut self,
|
||||
item: Self::Item,
|
||||
dst: &mut BytesMut,
|
||||
) -> Result<(), Self::Error> {
|
||||
match item {
|
||||
Message::Item(res) => {
|
||||
|
@ -334,7 +334,9 @@ pub(crate) struct HeaderIndex {
|
||||
|
||||
impl HeaderIndex {
|
||||
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;
|
||||
for (header, indices) in headers.iter().zip(indices.iter_mut()) {
|
||||
@ -491,7 +493,10 @@ macro_rules! byte (
|
||||
|
||||
impl ChunkedState {
|
||||
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> {
|
||||
use self::ChunkedState::*;
|
||||
match *self {
|
||||
@ -554,7 +559,8 @@ impl ChunkedState {
|
||||
}
|
||||
}
|
||||
fn read_size_lf(
|
||||
rdr: &mut BytesMut, size: &mut u64,
|
||||
rdr: &mut BytesMut,
|
||||
size: &mut u64,
|
||||
) -> Poll<ChunkedState, io::Error> {
|
||||
match byte!(rdr) {
|
||||
b'\n' if *size > 0 => Ok(Async::Ready(ChunkedState::Body)),
|
||||
@ -567,7 +573,9 @@ impl ChunkedState {
|
||||
}
|
||||
|
||||
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> {
|
||||
trace!("Chunked read, remaining={:?}", rem);
|
||||
|
||||
|
@ -90,7 +90,10 @@ where
|
||||
|
||||
/// Create http/1 dispatcher with slow request timeout.
|
||||
pub fn with_timeout(
|
||||
stream: T, config: ServiceConfig, timeout: Option<Delay>, service: S,
|
||||
stream: T,
|
||||
config: ServiceConfig,
|
||||
timeout: Option<Delay>,
|
||||
service: S,
|
||||
) -> Self {
|
||||
let keepalive = config.keep_alive_enabled();
|
||||
let flags = if keepalive {
|
||||
@ -173,19 +176,15 @@ where
|
||||
// process
|
||||
loop {
|
||||
let state = match self.state {
|
||||
State::None => loop {
|
||||
break if let Some(msg) = self.messages.pop_front() {
|
||||
State::None => if let Some(msg) = self.messages.pop_front() {
|
||||
match msg {
|
||||
DispatcherMessage::Item(req) => {
|
||||
Some(self.handle_request(req)?)
|
||||
}
|
||||
DispatcherMessage::Item(req) => Some(self.handle_request(req)?),
|
||||
DispatcherMessage::Error(res) => Some(State::SendResponse(
|
||||
Some((Message::Item(res), Body::Empty)),
|
||||
)),
|
||||
}
|
||||
} else {
|
||||
None
|
||||
};
|
||||
},
|
||||
// call inner service
|
||||
State::ServiceCall(ref mut fut) => {
|
||||
@ -255,7 +254,7 @@ where
|
||||
.framed
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.start_send(Message::Chunk(Some(item.into())))
|
||||
.start_send(Message::Chunk(Some(item)))
|
||||
{
|
||||
Ok(AsyncSink::Ready) => {
|
||||
self.flags.remove(Flags::FLUSHED);
|
||||
@ -299,7 +298,8 @@ where
|
||||
}
|
||||
|
||||
fn handle_request(
|
||||
&mut self, req: Request,
|
||||
&mut self,
|
||||
req: Request,
|
||||
) -> Result<State<S>, DispatchError<S::Error>> {
|
||||
let mut task = self.service.call(req);
|
||||
match task.poll().map_err(DispatchError::Service)? {
|
||||
@ -324,7 +324,7 @@ where
|
||||
}
|
||||
|
||||
let mut updated = false;
|
||||
'outer: loop {
|
||||
loop {
|
||||
match self.framed.as_mut().unwrap().poll() {
|
||||
Ok(Async::Ready(Some(msg))) => {
|
||||
updated = true;
|
||||
|
@ -107,7 +107,9 @@ impl ResponseEncoder {
|
||||
}
|
||||
|
||||
fn streaming_encoding(
|
||||
&mut self, version: Version, resp: &mut Response,
|
||||
&mut self,
|
||||
version: Version,
|
||||
resp: &mut Response,
|
||||
) -> TransferEncoding {
|
||||
match resp.chunked() {
|
||||
Some(true) => {
|
||||
|
@ -253,7 +253,7 @@ where
|
||||
type Future = Dispatcher<T, S>;
|
||||
|
||||
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 {
|
||||
|
@ -690,9 +690,10 @@ impl ResponseBuilder {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
#[cfg_attr(feature = "cargo-clippy", allow(clippy::borrowed_box))]
|
||||
#[cfg_attr(feature = "cargo-clippy", allow(borrowed_box))]
|
||||
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>> {
|
||||
if err.is_some() {
|
||||
return None;
|
||||
@ -871,7 +872,8 @@ impl ResponsePool {
|
||||
|
||||
#[inline]
|
||||
pub fn get_builder(
|
||||
pool: &'static ResponsePool, status: StatusCode,
|
||||
pool: &'static ResponsePool,
|
||||
status: StatusCode,
|
||||
) -> ResponseBuilder {
|
||||
if let Some(mut msg) = pool.0.borrow_mut().pop_front() {
|
||||
msg.status = status;
|
||||
@ -894,7 +896,9 @@ impl ResponsePool {
|
||||
|
||||
#[inline]
|
||||
pub fn get_response(
|
||||
pool: &'static ResponsePool, status: StatusCode, body: Body,
|
||||
pool: &'static ResponsePool,
|
||||
status: StatusCode,
|
||||
body: Body,
|
||||
) -> Response {
|
||||
if let Some(mut msg) = pool.0.borrow_mut().pop_front() {
|
||||
msg.status = status;
|
||||
|
@ -97,12 +97,10 @@ where
|
||||
}
|
||||
match self.framed.as_mut().unwrap().poll_complete() {
|
||||
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),
|
||||
Err(_) => {
|
||||
return Err((self.err.take().unwrap(), self.framed.take().unwrap()))
|
||||
}
|
||||
Err(_) => Err((self.err.take().unwrap(), self.framed.take().unwrap())),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -137,13 +137,13 @@ where
|
||||
let fut = Box::new(
|
||||
self.connector
|
||||
.call(connect)
|
||||
.map_err(|e| ClientError::from(e))
|
||||
.map_err(ClientError::from)
|
||||
.and_then(move |io| {
|
||||
// h1 protocol
|
||||
let framed = Framed::new(io, h1::ClientCodec::default());
|
||||
framed
|
||||
.send(request.into())
|
||||
.map_err(|e| ClientError::from(e))
|
||||
.map_err(ClientError::from)
|
||||
.and_then(|framed| {
|
||||
framed
|
||||
.into_future()
|
||||
|
@ -13,7 +13,9 @@ pub struct Parser;
|
||||
|
||||
impl Parser {
|
||||
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> {
|
||||
let chunk_len = src.len();
|
||||
|
||||
@ -86,7 +88,9 @@ impl Parser {
|
||||
|
||||
/// Parse the input stream into a frame.
|
||||
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> {
|
||||
// try to parse ws frame metadata
|
||||
let (idx, finished, opcode, length, mask) =
|
||||
@ -148,7 +152,11 @@ impl Parser {
|
||||
|
||||
/// Generate binary representation
|
||||
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 one: u8 = if fin {
|
||||
|
@ -1,5 +1,5 @@
|
||||
//! 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::slice;
|
||||
|
||||
@ -19,7 +19,7 @@ impl<'a> ShortSlice<'a> {
|
||||
|
||||
/// Faster version of `apply_mask()` which operates on 8-byte blocks.
|
||||
#[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) {
|
||||
// Extend the mask to 64 bits
|
||||
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
|
||||
// inefficient, it could be done better. The compiler does not understand that
|
||||
// a `ShortSlice` must be smaller than a u64.
|
||||
#[cfg_attr(
|
||||
feature = "cargo-clippy",
|
||||
allow(clippy::needless_pass_by_value)
|
||||
)]
|
||||
#[cfg_attr(feature = "cargo-clippy", allow(needless_pass_by_value))]
|
||||
fn xor_short(buf: ShortSlice, mask: u64) {
|
||||
// Unsafe: we know that a `ShortSlice` fits in a u64
|
||||
unsafe {
|
||||
|
Loading…
Reference in New Issue
Block a user