Skip to content

Commit 81f3afb

Browse files
committed
default,locator: predicate takes ref to NodeRef
The predicate is more convenient for use in this form, because methods such as `filter()` expect predicates to take values by reference. It makes implementation in the following commit more elegant. However, it unfortunately brings a breaking change.
1 parent 40aaee6 commit 81f3afb

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

scylla/src/transport/load_balancing/default.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -396,13 +396,13 @@ impl DefaultPolicy {
396396
fn make_rack_predicate<'a>(
397397
predicate: impl Fn(&NodeRef<'a>) -> bool + 'a,
398398
replica_location: ReplicaLocationCriteria<'a>,
399-
) -> impl Fn(NodeRef<'a>) -> bool {
399+
) -> impl Fn(&NodeRef<'a>) -> bool {
400400
move |node| match replica_location {
401401
ReplicaLocationCriteria::Any | ReplicaLocationCriteria::Datacenter(_) => {
402-
predicate(&node)
402+
predicate(node)
403403
}
404404
ReplicaLocationCriteria::DatacenterAndRack(_, rack) => {
405-
predicate(&node) && node.rack.as_deref() == Some(rack)
405+
predicate(node) && node.rack.as_deref() == Some(rack)
406406
}
407407
}
408408
}

scylla/src/transport/locator/mod.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -244,19 +244,17 @@ impl<'a> ReplicaSet<'a> {
244244
pub fn choose_filtered<R>(
245245
self,
246246
rng: &mut R,
247-
predicate: impl Fn(NodeRef<'a>) -> bool,
247+
predicate: impl Fn(&NodeRef<'a>) -> bool,
248248
) -> Option<NodeRef<'a>>
249249
where
250250
R: Rng + ?Sized,
251251
{
252252
let happy = self.choose(rng)?;
253-
if predicate(happy) {
253+
if predicate(&happy) {
254254
return Some(happy);
255255
}
256256

257-
self.into_iter()
258-
.filter(|node_ref| predicate(node_ref))
259-
.choose(rng)
257+
self.into_iter().filter(predicate).choose(rng)
260258
}
261259

262260
/// Gets the size of the set.

0 commit comments

Comments
 (0)