Skip to content

Commit ae167e5

Browse files
authored
Merge pull request capnproto#354 from danieleades/clippy/use-self
use 'Self' keyword to refer to own type
2 parents 8ead5d3 + dd4e923 commit ae167e5

File tree

24 files changed

+784
-817
lines changed

24 files changed

+784
-817
lines changed

async-byte-channel/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ struct Inner {
1818
}
1919

2020
impl Inner {
21-
fn new() -> Inner {
22-
Inner {
21+
fn new() -> Self {
22+
Self {
2323
buffer: vec![0; 8096],
2424
write_cursor: 0,
2525
read_cursor: 0,

benchmark/benchmark.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,8 @@ pub struct UseScratch {
162162
}
163163

164164
impl UseScratch {
165-
pub fn new() -> UseScratch {
166-
UseScratch {
165+
pub fn new() -> Self {
166+
Self {
167167
buffer1: capnp::Word::allocate_zeroed_vec(SCRATCH_SIZE),
168168
buffer2: capnp::Word::allocate_zeroed_vec(SCRATCH_SIZE),
169169
}
@@ -174,7 +174,7 @@ impl<'a> Scratch<'a> for UseScratch {
174174
type Allocator = message::ScratchSpaceHeapAllocator<'a>;
175175

176176
fn get_allocators(&'a mut self) -> (Self::Allocator, Self::Allocator) {
177-
let UseScratch { buffer1, buffer2 } = self;
177+
let Self { buffer1, buffer2 } = self;
178178
(
179179
message::ScratchSpaceHeapAllocator::new(capnp::Word::words_to_bytes_mut(buffer1)),
180180
message::ScratchSpaceHeapAllocator::new(capnp::Word::words_to_bytes_mut(buffer2)),
@@ -374,13 +374,13 @@ pub enum Mode {
374374
}
375375

376376
impl Mode {
377-
pub fn parse(s: &str) -> ::capnp::Result<Mode> {
377+
pub fn parse(s: &str) -> ::capnp::Result<Self> {
378378
match s {
379-
"object" => Ok(Mode::Object),
380-
"bytes" => Ok(Mode::Bytes),
381-
"client" => Ok(Mode::Client),
382-
"server" => Ok(Mode::Server),
383-
"pipe" => Ok(Mode::Pipe),
379+
"object" => Ok(Self::Object),
380+
"bytes" => Ok(Self::Bytes),
381+
"client" => Ok(Self::Client),
382+
"server" => Ok(Self::Server),
383+
"pipe" => Ok(Self::Pipe),
384384
s => Err(::capnp::Error::failed(format!("unrecognized mode: {}", s))),
385385
}
386386
}

benchmark/common.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ pub struct FastRand {
3030
}
3131

3232
impl FastRand {
33-
pub fn new() -> FastRand {
34-
FastRand {
33+
pub fn new() -> Self {
34+
Self {
3535
x: 0x1d2acd47,
3636
y: 0x58ca3e14,
3737
z: 0xf563f232,

capnp-futures/src/serialize.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -552,8 +552,8 @@ pub mod test {
552552
where
553553
R: Read,
554554
{
555-
pub(crate) fn new(read: R, blocking_period: usize) -> BlockingRead<R> {
556-
BlockingRead {
555+
pub(crate) fn new(read: R, blocking_period: usize) -> Self {
556+
Self {
557557
read,
558558
blocking_period,
559559
idx: 0,
@@ -605,8 +605,8 @@ pub mod test {
605605
where
606606
W: Write,
607607
{
608-
pub(crate) fn new(writer: W, blocking_period: usize) -> BlockingWrite<W> {
609-
BlockingWrite {
608+
pub(crate) fn new(writer: W, blocking_period: usize) -> Self {
609+
Self {
610610
writer,
611611
blocking_period,
612612
idx: 0,

capnp-futures/src/serialize_packed.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ where
8585
cx: &mut std::task::Context<'_>,
8686
outbuf: &mut [u8],
8787
) -> Poll<std::result::Result<usize, std::io::Error>> {
88-
let PackedRead {
88+
let Self {
8989
stage,
9090
inner,
9191
buf,
@@ -316,7 +316,7 @@ where
316316
mut inbuf: &[u8],
317317
) -> Poll<std::result::Result<usize, std::io::Error>> {
318318
let mut inbuf_bytes_consumed: usize = 0;
319-
let PackedWrite {
319+
let Self {
320320
stage,
321321
inner,
322322
buf,

capnp-futures/src/write_queue.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ impl<M> Clone for Sender<M>
4545
where
4646
M: AsOutputSegments,
4747
{
48-
fn clone(&self) -> Sender<M> {
49-
Sender {
48+
fn clone(&self) -> Self {
49+
Self {
5050
sender: self.sender.clone(),
5151
}
5252
}

capnp-rpc/examples/calculator/server.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ struct ValueImpl {
3535
}
3636

3737
impl ValueImpl {
38-
fn new(value: f64) -> ValueImpl {
39-
ValueImpl { value: value }
38+
fn new(value: f64) -> Self {
39+
Self { value: value }
4040
}
4141
}
4242

@@ -96,11 +96,8 @@ struct FunctionImpl {
9696
}
9797

9898
impl FunctionImpl {
99-
fn new(
100-
param_count: u32,
101-
body: calculator::expression::Reader,
102-
) -> ::capnp::Result<FunctionImpl> {
103-
let mut result = FunctionImpl {
99+
fn new(param_count: u32, body: calculator::expression::Reader) -> ::capnp::Result<Self> {
100+
let mut result = Self {
104101
param_count: param_count,
105102
body: ::capnp_rpc::ImbuedMessageBuilder::new(::capnp::message::HeapAllocator::new()),
106103
};

capnp-rpc/examples/pubsub/server.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ struct SubscriberMap {
4040
}
4141

4242
impl SubscriberMap {
43-
fn new() -> SubscriberMap {
44-
SubscriberMap {
43+
fn new() -> Self {
44+
Self {
4545
subscribers: HashMap::new(),
4646
}
4747
}
@@ -53,8 +53,8 @@ struct SubscriptionImpl {
5353
}
5454

5555
impl SubscriptionImpl {
56-
fn new(id: u64, subscribers: Rc<RefCell<SubscriberMap>>) -> SubscriptionImpl {
57-
SubscriptionImpl {
56+
fn new(id: u64, subscribers: Rc<RefCell<SubscriberMap>>) -> Self {
57+
Self {
5858
id: id,
5959
subscribers: subscribers,
6060
}
@@ -76,10 +76,10 @@ struct PublisherImpl {
7676
}
7777

7878
impl PublisherImpl {
79-
pub fn new() -> (PublisherImpl, Rc<RefCell<SubscriberMap>>) {
79+
pub fn new() -> (Self, Rc<RefCell<SubscriberMap>>) {
8080
let subscribers = Rc::new(RefCell::new(SubscriberMap::new()));
8181
(
82-
PublisherImpl {
82+
Self {
8383
next_id: 0,
8484
subscribers: subscribers.clone(),
8585
},

capnp-rpc/src/broken.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@ pub struct Pipeline {
3535
}
3636

3737
impl Pipeline {
38-
pub fn new(error: Error) -> Pipeline {
39-
Pipeline { error }
38+
pub fn new(error: Error) -> Self {
39+
Self { error }
4040
}
4141
}
4242

4343
impl PipelineHook for Pipeline {
4444
fn add_ref(&self) -> Box<dyn PipelineHook> {
45-
Box::new(Pipeline::new(self.error.clone()))
45+
Box::new(Self::new(self.error.clone()))
4646
}
4747
fn get_pipelined_cap(&self, _ops: &[PipelineOp]) -> Box<dyn ClientHook> {
4848
new_cap(self.error.clone())
@@ -56,8 +56,8 @@ pub struct Request {
5656
}
5757

5858
impl Request {
59-
pub fn new(error: Error, _size_hint: Option<::capnp::MessageSize>) -> Request {
60-
Request {
59+
pub fn new(error: Error, _size_hint: Option<::capnp::MessageSize>) -> Self {
60+
Self {
6161
error,
6262
message: ::capnp::message::Builder::new_default(),
6363
cap_table: Vec::new(),
@@ -97,8 +97,8 @@ pub struct Client {
9797
}
9898

9999
impl Client {
100-
pub fn new(error: Error, resolved: bool, brand: usize) -> Client {
101-
Client {
100+
pub fn new(error: Error, resolved: bool, brand: usize) -> Self {
101+
Self {
102102
inner: Rc::new(ClientInner {
103103
error,
104104
_resolved: resolved,
@@ -110,7 +110,7 @@ impl Client {
110110

111111
impl ClientHook for Client {
112112
fn add_ref(&self) -> Box<dyn ClientHook> {
113-
Box::new(Client {
113+
Box::new(Self {
114114
inner: self.inner.clone(),
115115
})
116116
}

capnp-rpc/src/lib.rs

+5-10
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ impl<VatId> RpcSystem<VatId> {
183183
pub fn new(
184184
mut network: Box<dyn crate::VatNetwork<VatId>>,
185185
bootstrap: Option<::capnp::capability::Client>,
186-
) -> RpcSystem<VatId> {
186+
) -> Self {
187187
let bootstrap_cap = match bootstrap {
188188
Some(cap) => cap.hook,
189189
None => broken::new_cap(Error::failed("no bootstrap capability".to_string())),
@@ -208,7 +208,7 @@ impl<VatId> RpcSystem<VatId> {
208208
Promise::ok(())
209209
}));
210210

211-
let mut result = RpcSystem {
211+
let mut result = Self {
212212
network,
213213
bootstrap_cap,
214214
connection_state: Rc::new(RefCell::new(None)),
@@ -233,7 +233,7 @@ impl<VatId> RpcSystem<VatId> {
233233
return T::new(self.bootstrap_cap.clone());
234234
}
235235
};
236-
let connection_state = RpcSystem::get_connection_state(
236+
let connection_state = Self::get_connection_state(
237237
&self.connection_state,
238238
self.bootstrap_cap.clone(),
239239
connection,
@@ -250,12 +250,7 @@ impl<VatId> RpcSystem<VatId> {
250250
let bootstrap_cap = self.bootstrap_cap.clone();
251251
let handle = self.handle.clone();
252252
Promise::from_future(self.network.accept().map_ok(move |connection| {
253-
RpcSystem::get_connection_state(
254-
&connection_state_ref,
255-
bootstrap_cap,
256-
connection,
257-
handle,
258-
);
253+
Self::get_connection_state(&connection_state_ref, bootstrap_cap, connection, handle);
259254
}))
260255
}
261256

@@ -421,7 +416,7 @@ where
421416
A: ::capnp::message::Allocator,
422417
{
423418
pub fn new(allocator: A) -> Self {
424-
ImbuedMessageBuilder {
419+
Self {
425420
builder: ::capnp::message::Builder::new(allocator),
426421
cap_table: Vec::new(),
427422
}

0 commit comments

Comments
 (0)