Skip to content

Commit add8f96

Browse files
committed
[std::vec] Rename .head_opt() to .head(), drop the old .head() behavior
1 parent d25334d commit add8f96

File tree

2 files changed

+6
-29
lines changed

2 files changed

+6
-29
lines changed

src/libstd/str.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,7 @@ impl<'a> Iterator<char> for Normalizations<'a> {
666666
fn next(&mut self) -> Option<char> {
667667
use unicode::decompose::canonical_combining_class;
668668

669-
match self.buffer.head_opt() {
669+
match self.buffer.head() {
670670
Some(&(c, 0)) => {
671671
self.sorted = false;
672672
self.buffer.shift();

src/libstd/vec.rs

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -942,10 +942,8 @@ pub trait ImmutableVector<'a, T> {
942942
/// Returns the element of a vector at the given index, or `None` if the
943943
/// index is out of bounds
944944
fn get(&self, index: uint) -> Option<&'a T>;
945-
/// Returns the first element of a vector, failing if the vector is empty.
946-
fn head(&self) -> &'a T;
947945
/// Returns the first element of a vector, or `None` if it is empty
948-
fn head_opt(&self) -> Option<&'a T>;
946+
fn head(&self) -> Option<&'a T>;
949947
/// Returns all but the first element of a vector
950948
fn tail(&self) -> &'a [T];
951949
/// Returns all but the first `n' elements of a vector
@@ -1123,13 +1121,7 @@ impl<'a,T> ImmutableVector<'a, T> for &'a [T] {
11231121
}
11241122

11251123
#[inline]
1126-
fn head(&self) -> &'a T {
1127-
if self.len() == 0 { fail!("head: empty vector") }
1128-
&self[0]
1129-
}
1130-
1131-
#[inline]
1132-
fn head_opt(&self) -> Option<&'a T> {
1124+
fn head(&self) -> Option<&'a T> {
11331125
if self.len() == 0 { None } else { Some(&self[0]) }
11341126
}
11351127

@@ -3054,27 +3046,12 @@ mod tests {
30543046

30553047
#[test]
30563048
fn test_head() {
3057-
let mut a = ~[11];
3058-
assert_eq!(a.head(), &11);
3059-
a = ~[11, 12];
3060-
assert_eq!(a.head(), &11);
3061-
}
3062-
3063-
#[test]
3064-
#[should_fail]
3065-
fn test_head_empty() {
3066-
let a: ~[int] = ~[];
3067-
a.head();
3068-
}
3069-
3070-
#[test]
3071-
fn test_head_opt() {
30723049
let mut a = ~[];
3073-
assert_eq!(a.head_opt(), None);
3050+
assert_eq!(a.head(), None);
30743051
a = ~[11];
3075-
assert_eq!(a.head_opt().unwrap(), &11);
3052+
assert_eq!(a.head().unwrap(), &11);
30763053
a = ~[11, 12];
3077-
assert_eq!(a.head_opt().unwrap(), &11);
3054+
assert_eq!(a.head().unwrap(), &11);
30783055
}
30793056

30803057
#[test]

0 commit comments

Comments
 (0)