Skip to content

Commit

Permalink
Clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
fafhrd91 committed Sep 5, 2023
1 parent d06fded commit 19cc8ab
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 36 deletions.
8 changes: 2 additions & 6 deletions ntex-bytes/src/buf/buf_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ pub trait BufMut {
let d = self.chunk_mut();
l = cmp::min(s.len(), d.len());

ptr::copy_nonoverlapping(s.as_ptr(), d.as_mut_ptr() as *mut u8, l);
ptr::copy_nonoverlapping(s.as_ptr(), d.as_mut_ptr(), l);
}

src.advance(l);
Expand Down Expand Up @@ -228,11 +228,7 @@ pub trait BufMut {
let dst = self.chunk_mut();
cnt = cmp::min(dst.len(), src.len() - off);

ptr::copy_nonoverlapping(
src[off..].as_ptr(),
dst.as_mut_ptr() as *mut u8,
cnt,
);
ptr::copy_nonoverlapping(src[off..].as_ptr(), dst.as_mut_ptr(), cnt);

off += cnt;
}
Expand Down
12 changes: 2 additions & 10 deletions ntex-bytes/src/bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1607,11 +1607,7 @@ impl BufMut for BytesMut {
self.reserve(len);

unsafe {
ptr::copy_nonoverlapping(
src.as_ptr(),
self.chunk_mut().as_mut_ptr() as *mut u8,
len,
);
ptr::copy_nonoverlapping(src.as_ptr(), self.chunk_mut().as_mut_ptr(), len);
self.advance_mut(len);
}
}
Expand Down Expand Up @@ -2418,11 +2414,7 @@ impl BufMut for BytesVec {
self.reserve(len);

unsafe {
ptr::copy_nonoverlapping(
src.as_ptr(),
self.chunk_mut().as_mut_ptr() as *mut u8,
len,
);
ptr::copy_nonoverlapping(src.as_ptr(), self.chunk_mut().as_mut_ptr(), len);
self.advance_mut(len);
}
}
Expand Down
18 changes: 10 additions & 8 deletions ntex-io/src/testing.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
//! utilities and helpers for testing
use std::cell::{Cell, RefCell};
use std::sync::{Arc, Mutex};
use std::task::{ready, Context, Poll, Waker};
use std::{any, cmp, fmt, future::Future, io, mem, net, pin::Pin, rc::Rc};
use std::{any, cell::RefCell, cmp, fmt, future::Future, io, mem, net, pin::Pin, rc::Rc};

use ntex_bytes::{Buf, BufMut, Bytes, BytesVec};
use ntex_util::future::poll_fn;
Expand Down Expand Up @@ -32,7 +31,7 @@ impl fmt::Debug for AtomicWaker {
pub struct IoTest {
tp: Type,
peer_addr: Option<net::SocketAddr>,
state: Arc<Cell<State>>,
state: Arc<Mutex<RefCell<State>>>,
local: Arc<Mutex<RefCell<Channel>>>,
remote: Arc<Mutex<RefCell<Channel>>>,
}
Expand Down Expand Up @@ -68,6 +67,9 @@ struct Channel {
write: IoTestState,
}

unsafe impl Sync for Channel {}
unsafe impl Send for Channel {}

impl Channel {
fn is_closed(&self) -> bool {
self.flags.contains(IoTestFlags::CLOSED)
Expand All @@ -94,7 +96,7 @@ impl IoTest {
pub fn create() -> (IoTest, IoTest) {
let local = Arc::new(Mutex::new(RefCell::new(Channel::default())));
let remote = Arc::new(Mutex::new(RefCell::new(Channel::default())));
let state = Arc::new(Cell::new(State::default()));
let state = Arc::new(Mutex::new(RefCell::new(State::default())));

(
IoTest {
Expand All @@ -115,11 +117,11 @@ impl IoTest {
}

pub fn is_client_dropped(&self) -> bool {
self.state.get().client_dropped
self.state.lock().unwrap().borrow().client_dropped
}

pub fn is_server_dropped(&self) -> bool {
self.state.get().server_dropped
self.state.lock().unwrap().borrow().server_dropped
}

/// Check if channel is closed from remoote side
Expand Down Expand Up @@ -332,13 +334,13 @@ impl Clone for IoTest {

impl Drop for IoTest {
fn drop(&mut self) {
let mut state = self.state.get();
let mut state = *self.state.lock().unwrap().borrow();
match self.tp {
Type::Server => state.server_dropped = true,
Type::Client => state.client_dropped = true,
_ => (),
}
self.state.set(state);
*self.state.lock().unwrap().borrow_mut() = state;

let guard = self.remote.lock().unwrap();
let mut remote = guard.borrow_mut();
Expand Down
6 changes: 1 addition & 5 deletions ntex-service/src/ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,7 @@ impl<'a, S> Copy for ServiceCtx<'a, S> {}
impl<'a, S> Clone for ServiceCtx<'a, S> {
#[inline]
fn clone(&self) -> Self {
Self {
idx: self.idx,
waiters: self.waiters,
_t: marker::PhantomData,
}
*self
}
}

Expand Down
2 changes: 1 addition & 1 deletion ntex-util/src/services/extensions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl Extensions {

/// Add all items from other `Extensions`
pub fn extend(&mut self, other: Extensions) {
self.map.extend(other.map.into_iter());
self.map.extend(other.map);
}

#[inline]
Expand Down
2 changes: 1 addition & 1 deletion ntex/src/http/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ pub struct Connect {
#[derive(Clone)]
pub struct Client(Rc<ClientConfig>);

pub(self) struct ClientConfig {
struct ClientConfig {
pub(self) connector: Box<dyn HttpConnect>,
pub(self) headers: HeaderMap,
pub(self) timeout: Millis,
Expand Down
2 changes: 1 addition & 1 deletion ntex/src/http/encoding/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ mod encoder;
pub use self::decoder::Decoder;
pub use self::encoder::Encoder;

pub(self) struct Writer {
struct Writer {
buf: BytesMut,
}

Expand Down
6 changes: 3 additions & 3 deletions ntex/src/http/h1/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ pub(super) trait MessageType: Sized {
let mut pos = 0;
let mut has_date = false;
let mut remaining = dst.capacity() - dst.len();
let mut buf = dst.chunk_mut().as_mut_ptr() as *mut u8;
let mut buf = dst.chunk_mut().as_mut_ptr();
for (key, value) in headers {
match *key {
CONNECTION => continue,
Expand All @@ -138,7 +138,7 @@ pub(super) trait MessageType: Sized {
pos = 0;
dst.reserve(len * 2);
remaining = dst.capacity() - dst.len();
buf = dst.chunk_mut().as_mut_ptr() as *mut u8;
buf = dst.chunk_mut().as_mut_ptr();
}
copy_nonoverlapping(k.as_ptr(), buf, k_len);
buf = buf.add(k_len);
Expand All @@ -165,7 +165,7 @@ pub(super) trait MessageType: Sized {
pos = 0;
dst.reserve(len * 2);
remaining = dst.capacity() - dst.len();
buf = dst.chunk_mut().as_mut_ptr() as *mut u8;
buf = dst.chunk_mut().as_mut_ptr();
}
copy_nonoverlapping(k.as_ptr(), buf, k_len);
buf = buf.add(k_len);
Expand Down
2 changes: 1 addition & 1 deletion ntex/src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub enum ServerStatus {

/// Socket id token
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub(self) struct Token(usize);
struct Token(usize);

impl Token {
pub(self) fn next(&mut self) -> Token {
Expand Down

0 comments on commit 19cc8ab

Please sign in to comment.