mirror of
https://github.com/actix/actix-web.git
synced 2024-11-22 17:41:11 +00:00
clippy
This commit is contained in:
parent
6b3ea4fc61
commit
efdf3ab1c3
8 changed files with 26 additions and 47 deletions
|
@ -303,9 +303,9 @@ where
|
||||||
body: &impl MessageBody,
|
body: &impl MessageBody,
|
||||||
) -> Result<BodySize, DispatchError> {
|
) -> Result<BodySize, DispatchError> {
|
||||||
let size = body.size();
|
let size = body.size();
|
||||||
let mut this = self.project();
|
let this = self.project();
|
||||||
this.codec
|
this.codec
|
||||||
.encode(Message::Item((message, size)), &mut this.write_buf)
|
.encode(Message::Item((message, size)), this.write_buf)
|
||||||
.map_err(|err| {
|
.map_err(|err| {
|
||||||
if let Some(mut payload) = this.payload.take() {
|
if let Some(mut payload) = this.payload.take() {
|
||||||
payload.set_error(PayloadError::Incomplete(None));
|
payload.set_error(PayloadError::Incomplete(None));
|
||||||
|
@ -425,13 +425,13 @@ where
|
||||||
Poll::Ready(Some(Ok(item))) => {
|
Poll::Ready(Some(Ok(item))) => {
|
||||||
this.codec.encode(
|
this.codec.encode(
|
||||||
Message::Chunk(Some(item)),
|
Message::Chunk(Some(item)),
|
||||||
&mut this.write_buf,
|
this.write_buf,
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Poll::Ready(None) => {
|
Poll::Ready(None) => {
|
||||||
this.codec
|
this.codec
|
||||||
.encode(Message::Chunk(None), &mut this.write_buf)?;
|
.encode(Message::Chunk(None), this.write_buf)?;
|
||||||
// payload stream finished.
|
// payload stream finished.
|
||||||
// set state to None and handle next message
|
// set state to None and handle next message
|
||||||
this.state.set(State::None);
|
this.state.set(State::None);
|
||||||
|
@ -460,13 +460,13 @@ where
|
||||||
Poll::Ready(Some(Ok(item))) => {
|
Poll::Ready(Some(Ok(item))) => {
|
||||||
this.codec.encode(
|
this.codec.encode(
|
||||||
Message::Chunk(Some(item)),
|
Message::Chunk(Some(item)),
|
||||||
&mut this.write_buf,
|
this.write_buf,
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Poll::Ready(None) => {
|
Poll::Ready(None) => {
|
||||||
this.codec
|
this.codec
|
||||||
.encode(Message::Chunk(None), &mut this.write_buf)?;
|
.encode(Message::Chunk(None), this.write_buf)?;
|
||||||
// payload stream finished.
|
// payload stream finished.
|
||||||
// set state to None and handle next message
|
// set state to None and handle next message
|
||||||
this.state.set(State::None);
|
this.state.set(State::None);
|
||||||
|
@ -592,7 +592,7 @@ where
|
||||||
let mut updated = false;
|
let mut updated = false;
|
||||||
let mut this = self.as_mut().project();
|
let mut this = self.as_mut().project();
|
||||||
loop {
|
loop {
|
||||||
match this.codec.decode(&mut this.read_buf) {
|
match this.codec.decode(this.read_buf) {
|
||||||
Ok(Some(msg)) => {
|
Ok(Some(msg)) => {
|
||||||
updated = true;
|
updated = true;
|
||||||
this.flags.insert(Flags::STARTED);
|
this.flags.insert(Flags::STARTED);
|
||||||
|
|
|
@ -103,14 +103,9 @@ type ConnectCallback<IO> = dyn Fn(&IO, &mut Extensions);
|
||||||
///
|
///
|
||||||
/// # Implementation Details
|
/// # Implementation Details
|
||||||
/// Uses Option to reduce necessary allocations when merging with request extensions.
|
/// Uses Option to reduce necessary allocations when merging with request extensions.
|
||||||
|
#[derive(Default)]
|
||||||
pub(crate) struct OnConnectData(Option<Extensions>);
|
pub(crate) struct OnConnectData(Option<Extensions>);
|
||||||
|
|
||||||
impl Default for OnConnectData {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self(None)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl OnConnectData {
|
impl OnConnectData {
|
||||||
/// Construct by calling the on-connect callback with the underlying transport I/O.
|
/// Construct by calling the on-connect callback with the underlying transport I/O.
|
||||||
pub(crate) fn from_io<T>(
|
pub(crate) fn from_io<T>(
|
||||||
|
|
|
@ -25,8 +25,8 @@ pub fn apply_mask_fast32(buf: &mut [u8], mask: [u8; 4]) {
|
||||||
//
|
//
|
||||||
// un aligned prefix and suffix would be mask/unmask per byte.
|
// un aligned prefix and suffix would be mask/unmask per byte.
|
||||||
// proper aligned middle slice goes into fast path and operates on 4-byte blocks.
|
// proper aligned middle slice goes into fast path and operates on 4-byte blocks.
|
||||||
let (mut prefix, words, mut suffix) = unsafe { buf.align_to_mut::<u32>() };
|
let (prefix, words, suffix) = unsafe { buf.align_to_mut::<u32>() };
|
||||||
apply_mask_fallback(&mut prefix, mask);
|
apply_mask_fallback(prefix, mask);
|
||||||
let head = prefix.len() & 3;
|
let head = prefix.len() & 3;
|
||||||
let mask_u32 = if head > 0 {
|
let mask_u32 = if head > 0 {
|
||||||
if cfg!(target_endian = "big") {
|
if cfg!(target_endian = "big") {
|
||||||
|
@ -40,7 +40,7 @@ pub fn apply_mask_fast32(buf: &mut [u8], mask: [u8; 4]) {
|
||||||
for word in words.iter_mut() {
|
for word in words.iter_mut() {
|
||||||
*word ^= mask_u32;
|
*word ^= mask_u32;
|
||||||
}
|
}
|
||||||
apply_mask_fallback(&mut suffix, mask_u32.to_ne_bytes());
|
apply_mask_fallback(suffix, mask_u32.to_ne_bytes());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
|
@ -394,9 +394,7 @@ impl ResourceDef {
|
||||||
pub fn set_name(&mut self, name: impl Into<String>) {
|
pub fn set_name(&mut self, name: impl Into<String>) {
|
||||||
let name = name.into();
|
let name = name.into();
|
||||||
|
|
||||||
if name.is_empty() {
|
assert!(!name.is_empty(), "resource name should not be empty");
|
||||||
panic!("resource name should not be empty");
|
|
||||||
}
|
|
||||||
|
|
||||||
self.name = Some(name)
|
self.name = Some(name)
|
||||||
}
|
}
|
||||||
|
@ -978,9 +976,7 @@ impl ResourceDef {
|
||||||
|
|
||||||
let (name, pattern) = match param.find(':') {
|
let (name, pattern) = match param.find(':') {
|
||||||
Some(idx) => {
|
Some(idx) => {
|
||||||
if tail {
|
assert!(!tail, "custom regex is not supported for tail match");
|
||||||
panic!("custom regex is not supported for tail match");
|
|
||||||
}
|
|
||||||
|
|
||||||
let (name, pattern) = param.split_at(idx);
|
let (name, pattern) = param.split_at(idx);
|
||||||
(name, &pattern[1..])
|
(name, &pattern[1..])
|
||||||
|
@ -1087,12 +1083,12 @@ impl ResourceDef {
|
||||||
re.push_str(&escape(unprocessed));
|
re.push_str(&escape(unprocessed));
|
||||||
}
|
}
|
||||||
|
|
||||||
if dyn_segment_count > MAX_DYNAMIC_SEGMENTS {
|
assert!(
|
||||||
panic!(
|
dyn_segment_count <= MAX_DYNAMIC_SEGMENTS,
|
||||||
"Only {} dynamic segments are allowed, provided: {}",
|
"Only {} dynamic segments are allowed, provided: {}",
|
||||||
MAX_DYNAMIC_SEGMENTS, dyn_segment_count
|
MAX_DYNAMIC_SEGMENTS,
|
||||||
|
dyn_segment_count
|
||||||
);
|
);
|
||||||
}
|
|
||||||
|
|
||||||
// Store the pattern in capture group #1 to have context info outside it
|
// Store the pattern in capture group #1 to have context info outside it
|
||||||
let mut re = format!("({})", re);
|
let mut re = format!("({})", re);
|
||||||
|
|
|
@ -365,5 +365,5 @@ pub(crate) fn with_method(
|
||||||
fn input_and_compile_error(mut item: TokenStream, err: syn::Error) -> TokenStream {
|
fn input_and_compile_error(mut item: TokenStream, err: syn::Error) -> TokenStream {
|
||||||
let compile_err = TokenStream::from(err.to_compile_error());
|
let compile_err = TokenStream::from(err.to_compile_error());
|
||||||
item.extend(compile_err);
|
item.extend(compile_err);
|
||||||
return item;
|
item
|
||||||
}
|
}
|
||||||
|
|
|
@ -276,7 +276,7 @@ impl AcceptEncoding {
|
||||||
let mut encodings = raw
|
let mut encodings = raw
|
||||||
.replace(' ', "")
|
.replace(' ', "")
|
||||||
.split(',')
|
.split(',')
|
||||||
.filter_map(|l| AcceptEncoding::new(l))
|
.filter_map(AcceptEncoding::new)
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
encodings.sort();
|
encodings.sort();
|
||||||
|
|
|
@ -102,7 +102,7 @@ where
|
||||||
fn from_request(req: &HttpRequest, _: &mut Payload) -> Self::Future {
|
fn from_request(req: &HttpRequest, _: &mut Payload) -> Self::Future {
|
||||||
let error_handler = req
|
let error_handler = req
|
||||||
.app_data::<PathConfig>()
|
.app_data::<PathConfig>()
|
||||||
.and_then(|c| c.ehandler.clone());
|
.and_then(|c| c.err_handler.clone());
|
||||||
|
|
||||||
ready(
|
ready(
|
||||||
de::Deserialize::deserialize(PathDeserializer::new(req.match_info()))
|
de::Deserialize::deserialize(PathDeserializer::new(req.match_info()))
|
||||||
|
@ -158,9 +158,9 @@ where
|
||||||
/// );
|
/// );
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
#[derive(Clone)]
|
#[derive(Clone, Default)]
|
||||||
pub struct PathConfig {
|
pub struct PathConfig {
|
||||||
ehandler: Option<Arc<dyn Fn(PathError, &HttpRequest) -> Error + Send + Sync>>,
|
err_handler: Option<Arc<dyn Fn(PathError, &HttpRequest) -> Error + Send + Sync>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PathConfig {
|
impl PathConfig {
|
||||||
|
@ -169,17 +169,11 @@ impl PathConfig {
|
||||||
where
|
where
|
||||||
F: Fn(PathError, &HttpRequest) -> Error + Send + Sync + 'static,
|
F: Fn(PathError, &HttpRequest) -> Error + Send + Sync + 'static,
|
||||||
{
|
{
|
||||||
self.ehandler = Some(Arc::new(f));
|
self.err_handler = Some(Arc::new(f));
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for PathConfig {
|
|
||||||
fn default() -> Self {
|
|
||||||
PathConfig { ehandler: None }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use actix_router::ResourceDef;
|
use actix_router::ResourceDef;
|
||||||
|
|
|
@ -167,7 +167,7 @@ impl<T: DeserializeOwned> FromRequest for Query<T> {
|
||||||
/// .app_data(query_cfg)
|
/// .app_data(query_cfg)
|
||||||
/// .service(index);
|
/// .service(index);
|
||||||
/// ```
|
/// ```
|
||||||
#[derive(Clone)]
|
#[derive(Clone, Default)]
|
||||||
pub struct QueryConfig {
|
pub struct QueryConfig {
|
||||||
err_handler: Option<Arc<dyn Fn(QueryPayloadError, &HttpRequest) -> Error + Send + Sync>>,
|
err_handler: Option<Arc<dyn Fn(QueryPayloadError, &HttpRequest) -> Error + Send + Sync>>,
|
||||||
}
|
}
|
||||||
|
@ -183,12 +183,6 @@ impl QueryConfig {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for QueryConfig {
|
|
||||||
fn default() -> Self {
|
|
||||||
QueryConfig { err_handler: None }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use actix_http::http::StatusCode;
|
use actix_http::http::StatusCode;
|
||||||
|
|
Loading…
Reference in a new issue