Skip to content

Commit 84993c6

Browse files
committed
binary_search_by_key comparator returns reference
1 parent 99541be commit 84993c6

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

src/libcollections/slice.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,8 +1125,8 @@ impl<T> [T] {
11251125
#[stable(feature = "slice_binary_search_by_key", since = "1.10.0")]
11261126
#[inline]
11271127
pub fn binary_search_by_key<'a, B, F, Q: ?Sized>(&'a self, b: &Q, f: F) -> Result<usize, usize>
1128-
where F: FnMut(&'a T) -> B,
1129-
B: Borrow<Q>,
1128+
where F: FnMut(&'a T) -> &'a B,
1129+
B: Borrow<Q> + 'a,
11301130
Q: Ord
11311131
{
11321132
core_slice::SliceExt::binary_search_by_key(self, b, f)

src/libcore/slice/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ pub trait SliceExt {
131131

132132
#[stable(feature = "slice_binary_search_by_key", since = "1.10.0")]
133133
fn binary_search_by_key<'a, B, F, Q: ?Sized>(&'a self, b: &Q, f: F) -> Result<usize, usize>
134-
where F: FnMut(&'a Self::Item) -> B,
135-
B: Borrow<Q>,
134+
where F: FnMut(&'a Self::Item) -> &'a B,
135+
B: Borrow<Q> + 'a,
136136
Q: Ord;
137137

138138
#[stable(feature = "core", since = "1.6.0")]
@@ -612,8 +612,8 @@ impl<T> SliceExt for [T] {
612612

613613
#[inline]
614614
fn binary_search_by_key<'a, B, F, Q: ?Sized>(&'a self, b: &Q, mut f: F) -> Result<usize, usize>
615-
where F: FnMut(&'a Self::Item) -> B,
616-
B: Borrow<Q>,
615+
where F: FnMut(&'a Self::Item) -> &'a B,
616+
B: Borrow<Q> + 'a,
617617
Q: Ord
618618
{
619619
self.binary_search_by(|k| f(k).borrow().cmp(b))

src/test/run-pass/slice_binary_search.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ fn main() {
2424
];
2525

2626
let key: &str = "def";
27-
let r = xs.binary_search_by_key(&key, |e| &e.topic);
27+
let r = xs.binary_search_by_key(key, |e| &e.topic);
2828
assert_eq!(Ok(1), r.map(|i| i));
2929
}

0 commit comments

Comments
 (0)