Skip to content

Commit

Permalink
Merge pull request #340 from nyurik/inline-args
Browse files Browse the repository at this point in the history
Inline format args
  • Loading branch information
tatsuya6502 authored Nov 9, 2023
2 parents 31cfe4d + 0859e95 commit 2ea735d
Show file tree
Hide file tree
Showing 26 changed files with 145 additions and 182 deletions.
7 changes: 2 additions & 5 deletions MIGRATION-GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,7 @@ use moka::notification::ListenerFuture;
use moka::future::FutureExt;

let eviction_listener = move |k, v: PathBuf, cause| -> ListenerFuture {
println!(
"\n== An entry has been evicted. k: {:?}, v: {:?}, cause: {:?}",
k, v, cause
);
println!("\n== An entry has been evicted. k: {k:?}, v: {v:?}, cause: {cause:?}");
let file_mgr2 = Arc::clone(&file_mgr1);

// Create a Future that removes the data file at the path `v`.
Expand All @@ -224,7 +221,7 @@ let eviction_listener = move |k, v: PathBuf, cause| -> ListenerFuture {
// Remove the data file. We must handle error cases here to
// prevent the listener from panicking.
if let Err(_e) = mgr.remove_data_file(v.as_path()).await {
eprintln!("Failed to remove a data file at {:?}", v);
eprintln!("Failed to remove a data file at {v:?}");
}
}
// Convert the regular Future into ListenerFuture. This method is
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ use moka::sync::Cache;
use std::thread;

fn value(n: usize) -> String {
format!("value {}", n)
format!("value {n}")
}

fn main() {
Expand Down Expand Up @@ -282,7 +282,7 @@ async fn main() {
const NUM_KEYS_PER_TASK: usize = 64;
fn value(n: usize) -> String {
format!("value {}", n)
format!("value {n}")
}
// Create a cache that can store up to 10,000 entries.
Expand Down
2 changes: 1 addition & 1 deletion examples/async_example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ async fn main() {
const NUM_KEYS_PER_TASK: usize = 64;

fn value(n: usize) -> String {
format!("value {}", n)
format!("value {n}")
}

// Create a cache that can store up to 10,000 entries.
Expand Down
2 changes: 1 addition & 1 deletion examples/eviction_listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ fn main() {
.max_capacity(2)
.time_to_live(Duration::from_secs(1))
.eviction_listener(|key, value, cause| {
println!("Evicted ({:?},{:?}) because {:?}", key, value, cause)
println!("Evicted ({key:?},{value:?}) because {cause:?}")
})
.build();
// Overload capacity of the cache.
Expand Down
2 changes: 1 addition & 1 deletion examples/sync_example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use moka::sync::Cache;
use std::thread;

fn value(n: usize) -> String {
format!("value {}", n)
format!("value {n}")
}

fn main() {
Expand Down
2 changes: 1 addition & 1 deletion src/cht/map/bucket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ impl<'g, K: 'g, V: 'g> BucketArray<K, V> {
// We need to return here to see if rehashing is still needed.
return None;
}
Err(e @ TryLockError::Poisoned(_)) => panic!("{:?}", e),
Err(e @ TryLockError::Poisoned(_)) => panic!("{e:?}"),
};

let next_array = self.next_array(guard, rehash_op);
Expand Down
2 changes: 1 addition & 1 deletion src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl From<usize> for CacheRegion {
1 => Self::MainProbation,
2 => Self::MainProtected,
3 => Self::Other,
_ => panic!("No such CacheRegion variant for {}", n),
_ => panic!("No such CacheRegion variant for {n}"),
}
}
}
Expand Down
10 changes: 2 additions & 8 deletions src/common/concurrent/deques.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,7 @@ impl<K> Deques<K> {
unsafe { deq.move_to_back(node) };
}
} else {
panic!(
"move_to_back_ao_in_deque - node is not a member of {} deque. {:?}",
deq_name, p,
)
panic!("move_to_back_ao_in_deque - node is not a member of {deq_name} deque. {p:?}")
}
}
}
Expand Down Expand Up @@ -187,10 +184,7 @@ impl<K> Deques<K> {
deq.unlink_and_drop(node);
}
} else {
panic!(
"unlink_node - node is not a member of {} deque. {:?}",
deq_name, p
)
panic!("unlink_node - node is not a member of {deq_name} deque. {p:?}")
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/common/concurrent/entry_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ mod test {
if let Some(size) = expected {
assert_eq!(size_of::<EntryInfo<()>>(), size);
} else {
panic!("No expected size for {:?} with Rust version {}", arch, ver);
panic!("No expected size for {arch:?} with Rust version {ver}");
}
}
}
8 changes: 3 additions & 5 deletions src/common/timer_wheel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,9 +327,7 @@ impl<K> TimerWheel<K> {
let deque = &mut self.wheels[level][index];
debug_assert!(
deque.len() > 0,
"BUG: The queue is empty. level: {}, index: {}",
level,
index
"BUG: The queue is empty. level: {level}, index: {index}"
);

// Rotate the nodes in the queue until we see the sentinel at the back of the
Expand Down Expand Up @@ -661,15 +659,15 @@ mod tests {
let entry = maybe_entry.expect("entry is none");
match entry {
TimerEvent::Expired(node) => *node.element.entry_info().key_hash().key,
_ => panic!("Expected an expired entry. Got {:?}", entry),
_ => panic!("Expected an expired entry. Got {entry:?}"),
}
}

fn rescheduled_key(maybe_entry: Option<TimerEvent<u32>>) -> u32 {
let entry = maybe_entry.expect("entry is none");
match entry {
TimerEvent::Rescheduled(entry) => *entry.key_hash().key,
_ => panic!("Expected a rescheduled entry. Got {:?}", entry),
_ => panic!("Expected a rescheduled entry. Got {entry:?}"),
}
}

Expand Down
18 changes: 9 additions & 9 deletions src/future/base_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2718,8 +2718,7 @@ mod tests {
assert_eq!(
cache.inner.frequency_sketch.read().await.table_len(),
len as usize,
"{}",
name
"{name}"
);
}

Expand Down Expand Up @@ -2939,8 +2938,9 @@ mod tests {
new_duration.map(Duration::from_secs)
}
expected => {
panic!("Unexpected call to expire_after_create: caller_line {}, expected: {:?}",
line!(), expected
panic!(
"Unexpected call to expire_after_create: caller_line {}, expected: {expected:?}",
line!()
);
}
}
Expand Down Expand Up @@ -2992,9 +2992,8 @@ mod tests {
}
expected => {
panic!(
"Unexpected call to expire_after_read: caller_line {}, expected: {:?}",
line!(),
expected
"Unexpected call to expire_after_read: caller_line {}, expected: {expected:?}",
line!()
);
}
}
Expand Down Expand Up @@ -3037,8 +3036,9 @@ mod tests {
new_duration_secs.map(Duration::from_secs)
}
expected => {
panic!("Unexpected call to expire_after_update: caller_line {}, expected: {:?}",
line!(), expected
panic!(
"Unexpected call to expire_after_update: caller_line {}, expected: {expected:?}",
line!()
);
}
}
Expand Down
Loading

0 comments on commit 2ea735d

Please sign in to comment.