@@ -1713,7 +1713,7 @@ pub mod raw {
1713
1713
/// An owned, partially type-converted vector.
1714
1714
///
1715
1715
/// This struct takes two type parameters `T` and `U` which must be of the
1716
- /// same, non-zero size.
1716
+ /// same, non-zero size having the same minimal alignment .
1717
1717
///
1718
1718
/// No allocations are performed by usage, only a deallocation happens in the
1719
1719
/// destructor which should only run when unwinding.
@@ -1727,12 +1727,12 @@ pub mod raw {
1727
1727
///
1728
1728
/// # Example
1729
1729
///
1730
- /// ```rust
1731
- /// let pv = PartialVec::from_vec(vec![0u , 1]);
1730
+ /// ```ignore
1731
+ /// let pv = PartialVec::from_vec(vec![0u32 , 1]);
1732
1732
/// assert_eq!(pv.pop(), Some(0));
1733
1733
/// assert_eq!(pv.pop(), Some(1));
1734
1734
/// assert_eq!(pv.pop(), None);
1735
- /// pv.push(2u );
1735
+ /// pv.push(2u32 );
1736
1736
/// pv.push(3);
1737
1737
/// assert_eq!(pv.into_vec().as_slice(), &[2, 3]);
1738
1738
/// ```
@@ -1759,7 +1759,7 @@ pub mod raw {
1759
1759
//
1760
1760
// (h) The `min_align_of` of `T` and `U` is equal.
1761
1761
1762
- pub struct PartialVec < T , U > {
1762
+ struct PartialVec < T , U > {
1763
1763
vec : Vec < T > ,
1764
1764
1765
1765
start_u : * mut U ,
@@ -1773,8 +1773,9 @@ impl<T,U> PartialVec<T,U> {
1773
1773
///
1774
1774
/// # Failure
1775
1775
///
1776
- /// Fails if `T` and `U` have differing sizes or are zero-sized.
1777
- pub fn from_vec ( mut vec : Vec < T > ) -> PartialVec < T , U > {
1776
+ /// Fails if `T` and `U` have differing sizes, are zero-sized or have
1777
+ /// differing minimal alignments.
1778
+ fn from_vec ( mut vec : Vec < T > ) -> PartialVec < T , U > {
1778
1779
// FIXME: Assert statically that the types `T` and `U` have the same
1779
1780
// size.
1780
1781
//
@@ -1863,7 +1864,7 @@ impl<T,U> PartialVec<T,U> {
1863
1864
///
1864
1865
/// Fails if not enough `T`s were popped to have enough space for the new
1865
1866
/// `U`.
1866
- pub fn push ( & mut self , value : U ) {
1867
+ fn push ( & mut self , value : U ) {
1867
1868
// The assert assures that still `end_u <= start_t` (d) after
1868
1869
// the function.
1869
1870
assert ! ( self . end_u as * const ( ) < self . start_t as * const ( ) ,
@@ -1884,7 +1885,7 @@ impl<T,U> PartialVec<T,U> {
1884
1885
///
1885
1886
/// Fails if not all `T`s were popped, also fails if not the same amount of
1886
1887
/// `U`s was pushed before calling `unwrap`.
1887
- pub fn into_vec ( mut self ) -> Vec < U > {
1888
+ fn into_vec ( mut self ) -> Vec < U > {
1888
1889
// If `self.end_u == self.end_t`, we know from (e) that there are no
1889
1890
// more `T`s in `vec`, we also know that the whole length of `vec` is
1890
1891
// now used by `U`s, thus we can just interpret `vec` as a vector of
@@ -1944,27 +1945,28 @@ impl<T,U> Iterator<T> for PartialVec<T,U> {
1944
1945
1945
1946
impl < T > Vec < T > {
1946
1947
/// Converts a `Vec<T>` to a `Vec<U>` where `T` and `U` have the same
1947
- /// non-zero size.
1948
+ /// non-zero size and the same minimal alignment .
1948
1949
///
1949
1950
/// # Failure
1950
1951
///
1951
- /// Fails if `T` and `U` have differing sizes or are zero-sized.
1952
+ /// Fails if `T` and `U` have differing sizes, are zero-sized or have
1953
+ /// differing minimal alignments.
1952
1954
///
1953
1955
/// # Example
1954
1956
///
1955
- /// ```rust
1957
+ /// ```
1956
1958
/// let v = vec![0u, 1, 2];
1957
- /// let w = v.map_inplace (|i| i + 3);
1959
+ /// let w = v.map_in_place (|i| i + 3);
1958
1960
/// assert_eq!(w.as_slice(), &[3, 4, 5]);
1959
1961
///
1960
1962
/// let big_endian_u16s = vec![0x1122u16, 0x3344];
1961
- /// let u8s = big_endian_u16s.map_inplace (|x| [
1963
+ /// let u8s = big_endian_u16s.map_in_place (|x| [
1962
1964
/// ((x >> 8) & 0xff) as u8,
1963
1965
/// (x & 0xff) as u8
1964
1966
/// ]);
1965
1967
/// assert_eq!(u8s.as_slice(), &[[0x11, 0x22], [0x33, 0x44]]);
1966
1968
/// ```
1967
- pub fn map_inplace < U > ( self , f: |T | -> U ) -> Vec < U > {
1969
+ pub fn map_in_place < U > ( self , f: |T | -> U ) -> Vec < U > {
1968
1970
let mut pv = PartialVec :: from_vec ( self ) ;
1969
1971
loop {
1970
1972
let maybe_t = pv. pop ( ) ;
@@ -2309,15 +2311,15 @@ mod tests {
2309
2311
2310
2312
#[ test]
2311
2313
#[ should_fail]
2312
- fn test_map_inplace_incompatible_types_fail ( ) {
2314
+ fn test_map_inp_lace_incompatible_types_fail ( ) {
2313
2315
let v = vec ! [ 0 u, 1 , 2 ] ;
2314
- v. map_inplace ( |_| ( ) ) ;
2316
+ v. map_in_place ( |_| ( ) ) ;
2315
2317
}
2316
2318
2317
2319
#[ test]
2318
- fn test_map_inplace ( ) {
2320
+ fn test_map_in_place ( ) {
2319
2321
let v = vec ! [ 0 u, 1 , 2 ] ;
2320
- assert_eq ! ( v. map_inplace ( |i: uint| i as int - 1 ) . as_slice( ) , & [ -1 i, 0 , 1 ] ) ;
2322
+ assert_eq ! ( v. map_in_place ( |i: uint| i as int - 1 ) . as_slice( ) , & [ -1 i, 0 , 1 ] ) ;
2321
2323
}
2322
2324
2323
2325
#[ bench]
0 commit comments