Skip to content

Commit

Permalink
Merge pull request capnproto#354 from danieleades/clippy/use-self
Browse files Browse the repository at this point in the history
use 'Self' keyword to refer to own type
  • Loading branch information
dwrensha authored Nov 22, 2022
2 parents 87c37cf + 732f269 commit 17f0354
Show file tree
Hide file tree
Showing 24 changed files with 784 additions and 817 deletions.
4 changes: 2 additions & 2 deletions async-byte-channel/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ struct Inner {
}

impl Inner {
fn new() -> Inner {
Inner {
fn new() -> Self {
Self {
buffer: vec![0; 8096],
write_cursor: 0,
read_cursor: 0,
Expand Down
18 changes: 9 additions & 9 deletions benchmark/benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ pub struct UseScratch {
}

impl UseScratch {
pub fn new() -> UseScratch {
UseScratch {
pub fn new() -> Self {
Self {
buffer1: capnp::Word::allocate_zeroed_vec(SCRATCH_SIZE),
buffer2: capnp::Word::allocate_zeroed_vec(SCRATCH_SIZE),
}
Expand All @@ -174,7 +174,7 @@ impl<'a> Scratch<'a> for UseScratch {
type Allocator = message::ScratchSpaceHeapAllocator<'a>;

fn get_allocators(&'a mut self) -> (Self::Allocator, Self::Allocator) {
let UseScratch { buffer1, buffer2 } = self;
let Self { buffer1, buffer2 } = self;
(
message::ScratchSpaceHeapAllocator::new(capnp::Word::words_to_bytes_mut(buffer1)),
message::ScratchSpaceHeapAllocator::new(capnp::Word::words_to_bytes_mut(buffer2)),
Expand Down Expand Up @@ -374,13 +374,13 @@ pub enum Mode {
}

impl Mode {
pub fn parse(s: &str) -> ::capnp::Result<Mode> {
pub fn parse(s: &str) -> ::capnp::Result<Self> {
match s {
"object" => Ok(Mode::Object),
"bytes" => Ok(Mode::Bytes),
"client" => Ok(Mode::Client),
"server" => Ok(Mode::Server),
"pipe" => Ok(Mode::Pipe),
"object" => Ok(Self::Object),
"bytes" => Ok(Self::Bytes),
"client" => Ok(Self::Client),
"server" => Ok(Self::Server),
"pipe" => Ok(Self::Pipe),
s => Err(::capnp::Error::failed(format!("unrecognized mode: {}", s))),
}
}
Expand Down
4 changes: 2 additions & 2 deletions benchmark/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ pub struct FastRand {
}

impl FastRand {
pub fn new() -> FastRand {
FastRand {
pub fn new() -> Self {
Self {
x: 0x1d2acd47,
y: 0x58ca3e14,
z: 0xf563f232,
Expand Down
8 changes: 4 additions & 4 deletions capnp-futures/src/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -552,8 +552,8 @@ pub mod test {
where
R: Read,
{
pub(crate) fn new(read: R, blocking_period: usize) -> BlockingRead<R> {
BlockingRead {
pub(crate) fn new(read: R, blocking_period: usize) -> Self {
Self {
read,
blocking_period,
idx: 0,
Expand Down Expand Up @@ -605,8 +605,8 @@ pub mod test {
where
W: Write,
{
pub(crate) fn new(writer: W, blocking_period: usize) -> BlockingWrite<W> {
BlockingWrite {
pub(crate) fn new(writer: W, blocking_period: usize) -> Self {
Self {
writer,
blocking_period,
idx: 0,
Expand Down
4 changes: 2 additions & 2 deletions capnp-futures/src/serialize_packed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ where
cx: &mut std::task::Context<'_>,
outbuf: &mut [u8],
) -> Poll<std::result::Result<usize, std::io::Error>> {
let PackedRead {
let Self {
stage,
inner,
buf,
Expand Down Expand Up @@ -316,7 +316,7 @@ where
mut inbuf: &[u8],
) -> Poll<std::result::Result<usize, std::io::Error>> {
let mut inbuf_bytes_consumed: usize = 0;
let PackedWrite {
let Self {
stage,
inner,
buf,
Expand Down
4 changes: 2 additions & 2 deletions capnp-futures/src/write_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ impl<M> Clone for Sender<M>
where
M: AsOutputSegments,
{
fn clone(&self) -> Sender<M> {
Sender {
fn clone(&self) -> Self {
Self {
sender: self.sender.clone(),
}
}
Expand Down
11 changes: 4 additions & 7 deletions capnp-rpc/examples/calculator/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ struct ValueImpl {
}

impl ValueImpl {
fn new(value: f64) -> ValueImpl {
ValueImpl { value: value }
fn new(value: f64) -> Self {
Self { value: value }
}
}

Expand Down Expand Up @@ -96,11 +96,8 @@ struct FunctionImpl {
}

impl FunctionImpl {
fn new(
param_count: u32,
body: calculator::expression::Reader,
) -> ::capnp::Result<FunctionImpl> {
let mut result = FunctionImpl {
fn new(param_count: u32, body: calculator::expression::Reader) -> ::capnp::Result<Self> {
let mut result = Self {
param_count: param_count,
body: ::capnp_rpc::ImbuedMessageBuilder::new(::capnp::message::HeapAllocator::new()),
};
Expand Down
12 changes: 6 additions & 6 deletions capnp-rpc/examples/pubsub/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ struct SubscriberMap {
}

impl SubscriberMap {
fn new() -> SubscriberMap {
SubscriberMap {
fn new() -> Self {
Self {
subscribers: HashMap::new(),
}
}
Expand All @@ -53,8 +53,8 @@ struct SubscriptionImpl {
}

impl SubscriptionImpl {
fn new(id: u64, subscribers: Rc<RefCell<SubscriberMap>>) -> SubscriptionImpl {
SubscriptionImpl {
fn new(id: u64, subscribers: Rc<RefCell<SubscriberMap>>) -> Self {
Self {
id: id,
subscribers: subscribers,
}
Expand All @@ -76,10 +76,10 @@ struct PublisherImpl {
}

impl PublisherImpl {
pub fn new() -> (PublisherImpl, Rc<RefCell<SubscriberMap>>) {
pub fn new() -> (Self, Rc<RefCell<SubscriberMap>>) {
let subscribers = Rc::new(RefCell::new(SubscriberMap::new()));
(
PublisherImpl {
Self {
next_id: 0,
subscribers: subscribers.clone(),
},
Expand Down
16 changes: 8 additions & 8 deletions capnp-rpc/src/broken.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ pub struct Pipeline {
}

impl Pipeline {
pub fn new(error: Error) -> Pipeline {
Pipeline { error }
pub fn new(error: Error) -> Self {
Self { error }
}
}

impl PipelineHook for Pipeline {
fn add_ref(&self) -> Box<dyn PipelineHook> {
Box::new(Pipeline::new(self.error.clone()))
Box::new(Self::new(self.error.clone()))
}
fn get_pipelined_cap(&self, _ops: &[PipelineOp]) -> Box<dyn ClientHook> {
new_cap(self.error.clone())
Expand All @@ -56,8 +56,8 @@ pub struct Request {
}

impl Request {
pub fn new(error: Error, _size_hint: Option<::capnp::MessageSize>) -> Request {
Request {
pub fn new(error: Error, _size_hint: Option<::capnp::MessageSize>) -> Self {
Self {
error,
message: ::capnp::message::Builder::new_default(),
cap_table: Vec::new(),
Expand Down Expand Up @@ -97,8 +97,8 @@ pub struct Client {
}

impl Client {
pub fn new(error: Error, resolved: bool, brand: usize) -> Client {
Client {
pub fn new(error: Error, resolved: bool, brand: usize) -> Self {
Self {
inner: Rc::new(ClientInner {
error,
_resolved: resolved,
Expand All @@ -110,7 +110,7 @@ impl Client {

impl ClientHook for Client {
fn add_ref(&self) -> Box<dyn ClientHook> {
Box::new(Client {
Box::new(Self {
inner: self.inner.clone(),
})
}
Expand Down
15 changes: 5 additions & 10 deletions capnp-rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ impl<VatId> RpcSystem<VatId> {
pub fn new(
mut network: Box<dyn crate::VatNetwork<VatId>>,
bootstrap: Option<::capnp::capability::Client>,
) -> RpcSystem<VatId> {
) -> Self {
let bootstrap_cap = match bootstrap {
Some(cap) => cap.hook,
None => broken::new_cap(Error::failed("no bootstrap capability".to_string())),
Expand All @@ -208,7 +208,7 @@ impl<VatId> RpcSystem<VatId> {
Promise::ok(())
}));

let mut result = RpcSystem {
let mut result = Self {
network,
bootstrap_cap,
connection_state: Rc::new(RefCell::new(None)),
Expand All @@ -233,7 +233,7 @@ impl<VatId> RpcSystem<VatId> {
return T::new(self.bootstrap_cap.clone());
}
};
let connection_state = RpcSystem::get_connection_state(
let connection_state = Self::get_connection_state(
&self.connection_state,
self.bootstrap_cap.clone(),
connection,
Expand All @@ -250,12 +250,7 @@ impl<VatId> RpcSystem<VatId> {
let bootstrap_cap = self.bootstrap_cap.clone();
let handle = self.handle.clone();
Promise::from_future(self.network.accept().map_ok(move |connection| {
RpcSystem::get_connection_state(
&connection_state_ref,
bootstrap_cap,
connection,
handle,
);
Self::get_connection_state(&connection_state_ref, bootstrap_cap, connection, handle);
}))
}

Expand Down Expand Up @@ -421,7 +416,7 @@ where
A: ::capnp::message::Allocator,
{
pub fn new(allocator: A) -> Self {
ImbuedMessageBuilder {
Self {
builder: ::capnp::message::Builder::new(allocator),
cap_table: Vec::new(),
}
Expand Down
Loading

0 comments on commit 17f0354

Please sign in to comment.