Skip to content

Commit 3e65295

Browse files
authored
Fixing clippy linter (#81)
1 parent 3197207 commit 3e65295

File tree

22 files changed

+162
-179
lines changed

22 files changed

+162
-179
lines changed

.github/workflows/main.yml

+6-2
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,15 @@ jobs:
1616
with:
1717
toolchain: nightly
1818
override: true
19-
components: rustfmt
19+
components: rustfmt, clippy
2020
- uses: actions-rs/cargo@v1
2121
with:
2222
command: fmt
23-
args: -- --check
23+
args: --all -- --check
24+
- uses: actions-rs/cargo@v1
25+
with:
26+
command: clippy
27+
args: --all-targets --all-features -- -D warnings
2428
- uses: actions-rs/cargo@v1
2529
with:
2630
command: build

.github/workflows/pr_main.yml

+6-2
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,15 @@ jobs:
1616
with:
1717
toolchain: nightly
1818
override: true
19-
components: rustfmt
19+
components: rustfmt, clippy
2020
- uses: actions-rs/cargo@v1
2121
with:
2222
command: fmt
23-
args: -- --check
23+
args: --all -- --check
24+
- uses: actions-rs/cargo@v1
25+
with:
26+
command: clippy
27+
args: --all-targets --all-features -- -D warnings
2428
- uses: actions-rs/cargo@v1
2529
with:
2630
command: build

abcf/src/entry/context/events.rs

+1-11
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,10 @@ impl<'a> EventContext<'a> {
1818
}
1919
}
2020

21+
#[derive(Default)]
2122
pub struct EventContextImpl {
2223
pub begin_block_events: Vec<abci::Event>,
2324
pub check_tx_events: Vec<abci::Event>,
2425
pub deliver_tx_events: Vec<abci::Event>,
2526
pub end_block_events: Vec<abci::Event>,
2627
}
27-
28-
impl Default for EventContextImpl {
29-
fn default() -> Self {
30-
Self {
31-
begin_block_events: Vec::new(),
32-
check_tx_events: Vec::new(),
33-
deliver_tx_events: Vec::new(),
34-
end_block_events: Vec::new(),
35-
}
36-
}
37-
}

abcf/src/entry/node.rs

+13-11
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ where
168168
}
169169
}
170170

171-
let events = mem::replace(&mut self.events.deliver_tx_events, Vec::new());
171+
let events = mem::take(&mut self.events.deliver_tx_events);
172172

173173
resp.events = events;
174174

@@ -185,9 +185,10 @@ where
185185
M: Module + Application + RPCs,
186186
{
187187
async fn init_chain(&mut self, _request: RequestInitChain) -> ResponseInitChain {
188-
let mut resp = ResponseInitChain::default();
189-
190-
resp.app_hash = self.stateful.root().expect("get app hash failed").to_vec();
188+
let resp = ResponseInitChain {
189+
app_hash: self.stateful.root().expect("get app hash failed").to_vec(),
190+
..Default::default()
191+
};
191192

192193
self.stateful
193194
.commit()
@@ -201,10 +202,11 @@ where
201202
}
202203

203204
async fn info(&mut self, _request: RequestInfo) -> ResponseInfo {
204-
let mut resp = ResponseInfo::default();
205-
206-
resp.version = String::from(self.module.metadata().impl_version);
207-
resp.app_version = self.module.metadata().version;
205+
let mut resp = ResponseInfo {
206+
version: String::from(self.module.metadata().impl_version),
207+
app_version: self.module.metadata().version,
208+
..Default::default()
209+
};
208210

209211
// compare height.
210212
let stateful_height = self
@@ -245,7 +247,7 @@ where
245247
}
246248

247249
async fn query(&mut self, request: RequestQuery) -> ResponseQuery {
248-
let mut paths = request.path.splitn(2, "/");
250+
let mut paths = request.path.splitn(2, '/');
249251

250252
let mut resp = ResponseQuery::default();
251253

@@ -321,7 +323,7 @@ where
321323

322324
self.module.begin_block(&mut ctx, req).await;
323325

324-
let events = mem::replace(begin_block_events, Vec::new());
326+
let events = mem::take(begin_block_events);
325327

326328
resp.events = events;
327329

@@ -348,7 +350,7 @@ where
348350
resp.consensus_param_updates = result.consensus_param_updates;
349351
resp.validator_updates = result.validator_updates;
350352

351-
let events = mem::replace(end_block_events, Vec::new());
353+
let events = mem::take(end_block_events);
352354

353355
resp.events = events;
354356

abcf/src/error.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ impl Error {
4141
Error::NoRPCMethod => 10006,
4242

4343
Error::TempOnlySupportRPC => 90001,
44-
Error::RPCApplicationError(code, _) => code.clone(),
45-
Error::ABCIApplicationError(code, _) => code.clone(),
44+
Error::RPCApplicationError(code, _) => *code,
45+
Error::ABCIApplicationError(code, _) => *code,
4646
Error::BS3Error(_) => 20001,
4747
}
4848
}

abcf/src/manager/manager.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ use crate::{
55
framework::{context::CallContext, EventContextImpl},
66
module::{Application, Module, ModuleMetadata, RPCs},
77
Error, ModuleError, ModuleResult, Result,
8-
};Ause alloc::collections::BTreeMap;
8+
};
9+
use alloc::collections::BTreeMap;
910
use alloc::{
1011
boxed::Box,
1112
string::{String, ToString},
@@ -194,7 +195,7 @@ impl<S: bs3::Store> tm_abci::Application for Node<S> {
194195
}
195196
}
196197

197-
let check_tx_events = mem::replace(&mut events.check_tx_events, Vec::new());
198+
let check_tx_events = mem::take(&mut events.check_tx_events);
198199

199200
match serde_json::to_vec(&data_map) {
200201
Ok(v) => resp.data = v,
@@ -227,7 +228,7 @@ impl<S: bs3::Store> tm_abci::Application for Node<S> {
227228
app.begin_block(&mut context, &req).await;
228229
}
229230

230-
let begin_block_events = mem::replace(&mut events.begin_block_events, Vec::new());
231+
let begin_block_events = mem::take(&mut events.begin_block_events);
231232

232233
abci::ResponseBeginBlock {
233234
events: begin_block_events,
@@ -275,7 +276,7 @@ impl<S: bs3::Store> tm_abci::Application for Node<S> {
275276
}
276277
}
277278

278-
let deliver_tx_events = mem::replace(&mut events.deliver_tx_events, Vec::new());
279+
let deliver_tx_events = mem::take(&mut events.deliver_tx_events);
279280

280281
match serde_json::to_vec(&data_map) {
281282
Ok(v) => resp.data = v,
@@ -317,7 +318,7 @@ impl<S: bs3::Store> tm_abci::Application for Node<S> {
317318
resp.consensus_param_updates = resp.consensus_param_updates;
318319
}
319320

320-
let end_block_events = mem::replace(&mut events.end_block_events, Vec::new());
321+
let end_block_events = mem::take(&mut events.end_block_events);
321322

322323
resp.validator_updates = validator_updates_vec;
323324
resp.events = end_block_events;

abcf/src/manager/mod.rs

+29
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,32 @@ pub use context::{
55

66
mod prelude;
77
pub use prelude::ModuleStorage;
8+
9+
/// Module.
10+
pub trait Module {
11+
fn metadata(&self) -> ModuleMetadata<'_>;
12+
}
13+
14+
pub enum ModuleType {
15+
Module,
16+
Manager,
17+
}
18+
19+
/// Metadata of module.
20+
pub struct ModuleMetadata<'a> {
21+
/// Name of module.
22+
pub name: &'a str,
23+
/// type of module.
24+
pub module_type: ModuleType,
25+
/// Version of module. If this version change, means module need update.
26+
pub version: u64,
27+
/// Version of impl. If this version change, means module only a change of impl.
28+
pub impl_version: &'a str,
29+
/// Genesis info.
30+
pub genesis: Genesis,
31+
}
32+
33+
/// Genesis for module.
34+
pub struct Genesis {
35+
pub target_height: u64,
36+
}

abcf/src/module/mod.rs

+29-3
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,34 @@ pub use events::{Event, EventAttr, EventValue};
1414
mod storages;
1515
pub use storages::{Merkle, Storage, StorageTransaction};
1616

17-
mod module;
18-
pub use module::{Genesis, Module, ModuleMetadata, ModuleType};
19-
2017
mod callable;
2118
pub use callable::Callable;
19+
20+
/// Module.
21+
pub trait Module {
22+
fn metadata(&self) -> ModuleMetadata<'_>;
23+
}
24+
25+
pub enum ModuleType {
26+
Module,
27+
Manager,
28+
}
29+
30+
/// Metadata of module.
31+
pub struct ModuleMetadata<'a> {
32+
/// Name of module.
33+
pub name: &'a str,
34+
/// type of module.
35+
pub module_type: ModuleType,
36+
/// Version of module. If this version change, means module need update.
37+
pub version: u64,
38+
/// Version of impl. If this version change, means module only a change of impl.
39+
pub impl_version: &'a str,
40+
/// Genesis info.
41+
pub genesis: Genesis,
42+
}
43+
44+
/// Genesis for module.
45+
pub struct Genesis {
46+
pub target_height: u64,
47+
}

abcf/src/module/module.rs

-28
This file was deleted.

macros/examples/event.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ fn main() {
2121

2222
if let Ok(abci_event) = e.to_abci_event() {
2323
assert_eq!(e.name(), "E");
24-
assert_eq!(abci_event.attributes[0].index, true);
25-
assert_eq!(abci_event.attributes[3].index, true);
24+
assert!(abci_event.attributes[0].index);
25+
assert!(abci_event.attributes[3].index);
2626

2727
assert_eq!(
2828
abci_event.attributes[0].key,

macros/examples/manager.rs

+3-19
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,9 @@ impl Application for DepModule {
2929
type Transaction = DepsTransaction;
3030
}
3131

32+
#[derive(Default)]
3233
pub struct DepsTransaction {}
3334

34-
impl Default for DepsTransaction {
35-
fn default() -> Self {
36-
Self {}
37-
}
38-
}
39-
4035
impl TryFrom<&SimpleNodeTransaction> for DepsTransaction {
4136
type Error = abcf::Error;
4237

@@ -81,27 +76,16 @@ impl Application for MockModule {
8176
}
8277
}
8378

79+
#[derive(Default)]
8480
pub struct MockTransaction {}
8581

86-
impl Default for MockTransaction {
87-
fn default() -> Self {
88-
MockTransaction {}
89-
}
90-
}
91-
92-
#[derive(Serialize, Deserialize)]
82+
#[derive(Default, Serialize, Deserialize)]
9383
pub struct SimpleNodeTransaction {
9484
pub v: u64,
9585
}
9686

9787
impl abcf::Transaction for SimpleNodeTransaction {}
9888

99-
impl Default for SimpleNodeTransaction {
100-
fn default() -> Self {
101-
Self { v: 0 }
102-
}
103-
}
104-
10589
impl abcf::module::FromBytes for SimpleNodeTransaction {
10690
fn from_bytes(bytes: &[u8]) -> abcf::Result<Self>
10791
where

macros/src/event.rs

+6-10
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,12 @@ pub fn event(input: TokenStream) -> TokenStream {
2121
parsed.fields.iter().for_each(|f| {
2222
let mut index = false;
2323
f.attrs.iter().for_each(|a| {
24-
a.path
25-
.segments
26-
.iter()
27-
.for_each(|s| match s.ident.to_string().as_str() {
28-
"abcf" => {
29-
index_is_false_str += &*(count.to_string() + ",");
30-
index = true;
31-
}
32-
_ => {}
33-
});
24+
a.path.segments.iter().for_each(|s| {
25+
if s.ident.to_string().as_str() == "abcf" {
26+
index_is_false_str += &*(count.to_string() + ",");
27+
index = true;
28+
}
29+
});
3430
});
3531
key_vec.push(f.ident.as_ref());
3632
key_str_vec.push(f.ident.clone().unwrap().to_string());

0 commit comments

Comments
 (0)