Skip to content

Commit af29337

Browse files
committed
PartialVec: Remove TODOs and rename unwrap to into_vec
1 parent dbc3cb3 commit af29337

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

src/libcollections/vec.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1710,9 +1710,6 @@ pub mod raw {
17101710
}
17111711
}
17121712

1713-
// TODO: Find some way to statically assert that `T` and `U` have the same
1714-
// size.
1715-
//
17161713
/// An owned, partially type-converted vector.
17171714
///
17181715
/// No allocations are performed by usage, only a deallocation happens in the
@@ -1734,7 +1731,7 @@ pub mod raw {
17341731
/// assert_eq!(pv.pop(), None);
17351732
/// pv.push(2u);
17361733
/// pv.push(3);
1737-
/// assert_eq!(pv.unwrap(), vec![2, 3]);
1734+
/// assert_eq!(pv.into_vec(), vec![2, 3]);
17381735
/// ```
17391736
//
17401737
// Upheld invariants:
@@ -1767,7 +1764,7 @@ pub struct PartialVec<T,U> {
17671764
impl<T,U> PartialVec<T,U> {
17681765
/// Creates a `PartialVec` from a `Vec`.
17691766
pub fn new(mut vec: Vec<T>) -> PartialVec<T,U> {
1770-
// TODO: do this statically
1767+
// FIXME: Assert that the types `T` and `U` have the same size.
17711768
assert!(mem::size_of::<T>() != 0);
17721769
assert!(mem::size_of::<U>() != 0);
17731770
assert!(mem::size_of::<T>() == mem::size_of::<U>());
@@ -1872,7 +1869,7 @@ impl<T,U> PartialVec<T,U> {
18721869
///
18731870
/// Fails if not all `T`s were popped, also fails if not the same amount of
18741871
/// `U`s was pushed before calling `unwrap`.
1875-
pub fn unwrap(self) -> Vec<U> {
1872+
pub fn into_vec(self) -> Vec<U> {
18761873
// If `self.end_u == self.end_t`, we know from (e) that there are no
18771874
// more `T`s in `vec`, we also know that the whole length of `vec` is
18781875
// now used by `U`s, thus we can just transmute `vec` from a vector of
@@ -1945,11 +1942,10 @@ impl<T> Vec<T> {
19451942
pub fn map_inplace<U>(self, f: |T| -> U) -> Vec<U> {
19461943
let mut pv = PartialVec::new(self);
19471944
loop {
1948-
// TODO: need this extra assignment for borrowck to pass
19491945
let maybe_t = pv.pop();
19501946
match maybe_t {
19511947
Some(t) => pv.push(f(t)),
1952-
None => return pv.unwrap(),
1948+
None => return pv.into_vec(),
19531949
};
19541950
}
19551951
}

0 commit comments

Comments
 (0)