Skip to content

Commit 36372b9

Browse files
committed
std: Export BinarySearchResult
At the same time remove the `pub use` of the variants in favor of accessing through the enum type itself. This is a breaking change as the `Found` and `NotFound` variants must now be imported through `BinarySearchResult` instead of just `std::slice`. [breaking-change] Closes #19272
1 parent 7222ba9 commit 36372b9

File tree

3 files changed

+12
-14
lines changed

3 files changed

+12
-14
lines changed

src/libcollections/slice.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ pub use core::slice::{OrdSlicePrelude, SlicePrelude, Items, MutItems};
106106
pub use core::slice::{ImmutableIntSlice, MutableIntSlice};
107107
pub use core::slice::{MutSplits, MutChunks, Splits};
108108
pub use core::slice::{bytes, mut_ref_slice, ref_slice, CloneSlicePrelude};
109-
pub use core::slice::{Found, NotFound, from_raw_buf, from_raw_mut_buf};
109+
pub use core::slice::{from_raw_buf, from_raw_mut_buf, BinarySearchResult};
110110

111111
// Functional utilities
112112

src/libcore/slice.rs

+8-10
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@
3434
// * The `raw` and `bytes` submodules.
3535
// * Boilerplate trait implementations.
3636

37-
pub use self::BinarySearchResult::*;
38-
3937
use mem::transmute;
4038
use clone::Clone;
4139
use cmp::{PartialEq, PartialOrd, Eq, Ord, Ordering, Less, Equal, Greater, Equiv};
@@ -219,7 +217,7 @@ pub trait SlicePrelude<T> for Sized? {
219217
/// found; the fourth could match any position in `[1,4]`.
220218
///
221219
/// ```rust
222-
/// use std::slice::{Found, NotFound};
220+
/// use std::slice::BinarySearchResult::{Found, NotFound};
223221
/// let s = [0i, 1, 1, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55];
224222
/// let s = s.as_slice();
225223
///
@@ -548,7 +546,7 @@ impl<T> SlicePrelude<T> for [T] {
548546
while lim != 0 {
549547
let ix = base + (lim >> 1);
550548
match f(&self[ix]) {
551-
Equal => return Found(ix),
549+
Equal => return BinarySearchResult::Found(ix),
552550
Less => {
553551
base = ix + 1;
554552
lim -= 1;
@@ -557,7 +555,7 @@ impl<T> SlicePrelude<T> for [T] {
557555
}
558556
lim >>= 1;
559557
}
560-
return NotFound(base);
558+
return BinarySearchResult::NotFound(base);
561559
}
562560

563561
#[inline]
@@ -838,7 +836,7 @@ pub trait OrdSlicePrelude<T: Ord> for Sized? {
838836
/// found; the fourth could match any position in `[1,4]`.
839837
///
840838
/// ```rust
841-
/// use std::slice::{Found, NotFound};
839+
/// use std::slice::BinarySearchResult::{Found, NotFound};
842840
/// let s = [0i, 1, 1, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55];
843841
/// let s = s.as_slice();
844842
///
@@ -1517,17 +1515,17 @@ impl BinarySearchResult {
15171515
/// Similar to `Result::ok`.
15181516
pub fn found(&self) -> Option<uint> {
15191517
match *self {
1520-
Found(i) => Some(i),
1521-
NotFound(_) => None
1518+
BinarySearchResult::Found(i) => Some(i),
1519+
BinarySearchResult::NotFound(_) => None
15221520
}
15231521
}
15241522

15251523
/// Convert a `Found` to `None`, `NotFound` to `Some`.
15261524
/// Similar to `Result::err`.
15271525
pub fn not_found(&self) -> Option<uint> {
15281526
match *self {
1529-
Found(_) => None,
1530-
NotFound(i) => Some(i)
1527+
BinarySearchResult::Found(_) => None,
1528+
BinarySearchResult::NotFound(i) => Some(i)
15311529
}
15321530
}
15331531
}

src/libregex/parse.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use std::cmp;
1818
use std::fmt;
1919
use std::iter;
2020
use std::num;
21-
use std::slice;
21+
use std::slice::BinarySearchResult;
2222

2323
/// Static data containing Unicode ranges for general categories and scripts.
2424
use unicode::regex::{UNICODE_CLASSES, PERLD, PERLS, PERLW};
@@ -1027,8 +1027,8 @@ fn is_valid_cap(c: char) -> bool {
10271027

10281028
fn find_class(classes: NamedClasses, name: &str) -> Option<Vec<(char, char)>> {
10291029
match classes.binary_search(|&(s, _)| s.cmp(name)) {
1030-
slice::Found(i) => Some(classes[i].val1().to_vec()),
1031-
slice::NotFound(_) => None,
1030+
BinarySearchResult::Found(i) => Some(classes[i].val1().to_vec()),
1031+
BinarySearchResult::NotFound(_) => None,
10321032
}
10331033
}
10341034

0 commit comments

Comments
 (0)