Skip to content

Commit 50cc55d

Browse files
committed
fix clippy issues
1 parent 3404b11 commit 50cc55d

File tree

2 files changed

+17
-23
lines changed
  • test_canisters/canister_upgraded/src/canister_upgraded_backend/src

2 files changed

+17
-23
lines changed

Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ candid = "0.10.14"
1111
ic-cdk = "0.18.5"
1212
ic-stable-structures = "0.7.0"
1313

14-
#stable-fs = "0.9.0"
15-
stable-fs = {path = "../stable-fs/stable-fs"}
14+
stable-fs = "0.9.0"
1615

1716
pocket-ic = "9.0.2"
1817
anyhow = "1.0.98"

test_canisters/canister_upgraded/src/canister_upgraded_backend/src/lib.rs

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ impl ic_stable_structures::Storable for MyChunk4k {
8181
}
8282

8383
thread_local! {
84-
static LARGE_CHUNK: RefCell<Option<MyChunk>> = RefCell::new(None);
84+
static LARGE_CHUNK: RefCell<Option<MyChunk>> = const { RefCell::new(None) };
8585

8686
static MAP: RefCell<StableBTreeMap<u64, MyChunk, Memory>> = RefCell::new(
8787
StableBTreeMap::init(MEMORY_MANAGER.with(|m| m.borrow().get(MemoryId::new(110))))
@@ -269,8 +269,8 @@ pub fn store_chunk_map4k(key: u64) -> (u64, usize) {
269269
let mut mp = mp.borrow_mut();
270270

271271
loop {
272-
let upper = std::cmp::min((&chunk.0).len(), ((idx + 1) * 4096) as usize);
273-
let lower = std::cmp::min((&chunk.0).len(), (idx * 4096) as usize);
272+
let upper = std::cmp::min(chunk.0.len(), ((idx + 1) * 4096) as usize);
273+
let lower = std::cmp::min(chunk.0.len(), (idx * 4096) as usize);
274274

275275
if lower == upper {
276276
break;
@@ -283,7 +283,7 @@ pub fn store_chunk_map4k(key: u64) -> (u64, usize) {
283283

284284
len += vec.len();
285285

286-
if vec.len() > 0 {
286+
if !vec.is_empty() {
287287
mp.insert((key, idx as u64), MyChunk4k(vec));
288288
} else {
289289
break;
@@ -459,7 +459,6 @@ fn append_text(filename: String, text: String, times: usize) -> u64 {
459459

460460
let file = OpenOptions::new()
461461
.create(true)
462-
.write(true)
463462
.append(true)
464463
.open(filename)
465464
.unwrap();
@@ -578,13 +577,11 @@ fn delete_folder(path: String) {
578577

579578
#[ic_cdk::query]
580579
fn current_dir() -> String {
581-
let res = env::current_dir()
580+
env::current_dir()
582581
.unwrap()
583582
.into_os_string()
584583
.into_string()
585-
.unwrap();
586-
587-
res
584+
.unwrap()
588585
}
589586

590587
#[ic_cdk::query]
@@ -608,8 +605,8 @@ fn list_files(path: String) -> Vec<String> {
608605
res
609606
}
610607

611-
fn list_all_files_recursive(path: &String, files: &mut Vec<String>) {
612-
let entries = fs::read_dir(&path).unwrap();
608+
fn list_all_files_recursive(path: &str, files: &mut Vec<String>) {
609+
let entries = fs::read_dir(path).unwrap();
613610

614611
for entry in entries {
615612
let entry = entry.unwrap();
@@ -627,7 +624,7 @@ fn list_all_files_recursive(path: &String, files: &mut Vec<String>) {
627624

628625
#[ic_cdk::query]
629626
fn list_all_files(path: String) -> Vec<String> {
630-
println!("Reading directory: {}", path);
627+
println!("Reading directory: {path}");
631628

632629
let mut res = vec![];
633630
list_all_files_recursive(&path, &mut res);
@@ -640,10 +637,10 @@ fn create_depth_folders(path: String, count: usize) -> String {
640637
let mut dir_name = "d0".to_string();
641638

642639
for num in 1..count {
643-
dir_name = format!("{}/d{}", dir_name, num);
640+
dir_name = format!("{dir_name}/d{num}");
644641
}
645642

646-
dir_name = format!("{}/{}", path, dir_name);
643+
dir_name = format!("{path}/{dir_name}");
647644

648645
fs::create_dir_all(&dir_name).unwrap();
649646

@@ -655,10 +652,10 @@ fn delete_depth_folders(path: String, count: usize) -> String {
655652
let mut dir_name = "d0".to_string();
656653

657654
for num in 1..count {
658-
dir_name = format!("{}/d{}", dir_name, num);
655+
dir_name = format!("{dir_name}/d{num}");
659656
}
660657

661-
dir_name = format!("{}/{}", path, dir_name);
658+
dir_name = format!("{path}/{dir_name}");
662659

663660
fs::remove_dir_all(&dir_name).unwrap();
664661

@@ -670,14 +667,12 @@ fn create_files(path: String, count: usize) -> u64 {
670667
let stime = ic_cdk::api::instruction_counter();
671668

672669
for num in 0..count {
673-
let filename = format!("{}/{}.txt", path, num);
670+
let filename = format!("{path}/{num}.txt");
674671
let mut file = File::create(&filename).unwrap();
675672

676673
// 64 byte block + file name
677-
let text = format!(
678-
"0123456789012345678901234567890123456789012345678901234567890123:{}",
679-
filename
680-
);
674+
let text =
675+
format!("0123456789012345678901234567890123456789012345678901234567890123:{filename}");
681676

682677
file.write_all(text.as_bytes()).unwrap();
683678
file.flush().unwrap();

0 commit comments

Comments
 (0)