Skip to content

Commit 158be28

Browse files
committed
---
yaml --- r: 151471 b: refs/heads/try2 c: eab6bb2 h: refs/heads/master i: 151469: b218e72 151467: 46d27b9 151463: 5d3efa2 151455: 4bda6a1 v: v3
1 parent c384dda commit 158be28

File tree

9 files changed

+82
-80
lines changed

9 files changed

+82
-80
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 752048a27135bdf15c6f00229b04cea7ceeaf739
8+
refs/heads/try2: eab6bb2ece0427d2ec165e510f2abaa84b857900
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/doc/guide-container.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,8 @@ Iterators offer generic conversion to containers with the `collect` adaptor:
266266

267267
~~~
268268
let xs = [0, 1, 1, 2, 3, 5, 8];
269-
let ys = xs.iter().rev().skip(1).map(|&x| x * 2).collect::<~[int]>();
270-
assert_eq!(ys, ~[10, 6, 4, 2, 2, 0]);
269+
let ys = xs.iter().rev().skip(1).map(|&x| x * 2).collect::<Vec<int>>();
270+
assert_eq!(ys, vec![10, 6, 4, 2, 2, 0]);
271271
~~~
272272

273273
The method requires a type hint for the container type, if the surrounding code
@@ -278,14 +278,14 @@ implementing the `FromIterator` trait. For example, the implementation for
278278
vectors is as follows:
279279

280280
~~~ {.ignore}
281-
impl<A> FromIterator<A> for ~[A] {
282-
pub fn from_iter<T: Iterator<A>>(iterator: &mut T) -> ~[A] {
281+
impl<T> FromIterator<T> for Vec<T> {
282+
fn from_iter<I:Iterator<A>>(mut iterator: I) -> Vec<T> {
283283
let (lower, _) = iterator.size_hint();
284-
let mut xs = with_capacity(lower);
285-
for x in iterator {
286-
xs.push(x);
284+
let mut vector = Vec::with_capacity(lower);
285+
for element in iterator {
286+
vector.push(element);
287287
}
288-
xs
288+
vector
289289
}
290290
}
291291
~~~

branches/try2/src/doc/rust.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3598,18 +3598,18 @@ and the cast expression in `main`.
35983598
Within the body of an item that has type parameter declarations, the names of its type parameters are types:
35993599

36003600
~~~~
3601-
fn map<A: Clone, B: Clone>(f: |A| -> B, xs: &[A]) -> ~[B] {
3601+
fn map<A: Clone, B: Clone>(f: |A| -> B, xs: &[A]) -> Vec<B> {
36023602
if xs.len() == 0 {
3603-
return ~[];
3603+
return vec![];
36043604
}
36053605
let first: B = f(xs[0].clone());
3606-
let rest: ~[B] = map(f, xs.slice(1, xs.len()));
3607-
return ~[first] + rest;
3606+
let rest: Vec<B> = map(f, xs.slice(1, xs.len()));
3607+
return [first] + rest;
36083608
}
36093609
~~~~
36103610

36113611
Here, `first` has type `B`, referring to `map`'s `B` type parameter;
3612-
and `rest` has type `~[B]`, a vector type with element type `B`.
3612+
and `rest` has type `Vec<B>`, a vector type with element type `B`.
36133613

36143614
### Self types
36153615

branches/try2/src/doc/tutorial.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1588,8 +1588,8 @@ let mut numbers = vec![1, 2, 3];
15881588
numbers.push(4);
15891589
numbers.push(5);
15901590
1591-
// The type of a unique vector is written as `~[int]`
1592-
let more_numbers: ~[int] = numbers.move_iter().collect();
1591+
// The type of a unique vector is written as `Vec<int>`
1592+
let more_numbers: Vec<int> = numbers.move_iter().map(|i| i+1).collect();
15931593
15941594
// The original `numbers` value can no longer be used, due to move semantics.
15951595
@@ -1633,7 +1633,7 @@ view[0] = 5;
16331633
let ys: &mut [int] = &mut [1, 2, 3];
16341634
~~~
16351635

1636-
Square brackets denote indexing into a vector:
1636+
Square brackets denote indexing into a slice or fixed-size vector:
16371637

16381638
~~~~
16391639
# enum Crayon { Almond, AntiqueBrass, Apricot,
@@ -1647,7 +1647,7 @@ match crayons[0] {
16471647
}
16481648
~~~~
16491649

1650-
A vector can be destructured using pattern matching:
1650+
A slice or fixed-size vector can be destructured using pattern matching:
16511651

16521652
~~~~
16531653
let numbers: &[int] = &[1, 2, 3];
@@ -1660,9 +1660,10 @@ let score = match numbers {
16601660
~~~~
16611661

16621662
Both vectors and strings support a number of useful [methods](#methods),
1663-
defined in [`std::vec`] and [`std::str`].
1663+
defined in [`std::vec`], [`std::slice`], and [`std::str`].
16641664

16651665
[`std::vec`]: std/vec/index.html
1666+
[`std::slice`]: std/slice/index.html
16661667
[`std::str`]: std/str/index.html
16671668

16681669
# Ownership escape hatches

branches/try2/src/libcore/iter.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -455,8 +455,8 @@ pub trait Iterator<A> {
455455
///
456456
/// ```rust
457457
/// let a = [1, 2, 3, 4, 5];
458-
/// let b: ~[int] = a.iter().map(|&x| x).collect();
459-
/// assert!(a == b);
458+
/// let b: Vec<int> = a.iter().map(|&x| x).collect();
459+
/// assert!(a.as_slice() == b.as_slice());
460460
/// ```
461461
#[inline]
462462
fn collect<B: FromIterator<A>>(&mut self) -> B {

branches/try2/src/libcore/str.rs

Lines changed: 54 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -621,12 +621,12 @@ impl<'a> Iterator<UTF16Item> for UTF16Items<'a> {
621621
/// 0x0073, 0xDD1E, 0x0069, 0x0063,
622622
/// 0xD834];
623623
///
624-
/// assert_eq!(str::utf16_items(v).collect::<~[_]>(),
625-
/// ~[ScalarValue('𝄞'),
626-
/// ScalarValue('m'), ScalarValue('u'), ScalarValue('s'),
627-
/// LoneSurrogate(0xDD1E),
628-
/// ScalarValue('i'), ScalarValue('c'),
629-
/// LoneSurrogate(0xD834)]);
624+
/// assert_eq!(str::utf16_items(v).collect::<Vec<_>>(),
625+
/// vec![ScalarValue('𝄞'),
626+
/// ScalarValue('m'), ScalarValue('u'), ScalarValue('s'),
627+
/// LoneSurrogate(0xDD1E),
628+
/// ScalarValue('i'), ScalarValue('c'),
629+
/// LoneSurrogate(0xD834)]);
630630
/// ```
631631
pub fn utf16_items<'a>(v: &'a [u16]) -> UTF16Items<'a> {
632632
UTF16Items { iter : v.iter() }
@@ -896,8 +896,8 @@ pub trait StrSlice<'a> {
896896
/// # Example
897897
///
898898
/// ```rust
899-
/// let v: ~[char] = "abc åäö".chars().collect();
900-
/// assert_eq!(v, ~['a', 'b', 'c', ' ', 'å', 'ä', 'ö']);
899+
/// let v: Vec<char> = "abc åäö".chars().collect();
900+
/// assert_eq!(v, vec!['a', 'b', 'c', ' ', 'å', 'ä', 'ö']);
901901
/// ```
902902
fn chars(&self) -> Chars<'a>;
903903

@@ -925,14 +925,14 @@ pub trait StrSlice<'a> {
925925
/// # Example
926926
///
927927
/// ```rust
928-
/// let v: ~[&str] = "Mary had a little lamb".split(' ').collect();
929-
/// assert_eq!(v, ~["Mary", "had", "a", "little", "lamb"]);
928+
/// let v: Vec<&str> = "Mary had a little lamb".split(' ').collect();
929+
/// assert_eq!(v, vec!["Mary", "had", "a", "little", "lamb"]);
930930
///
931-
/// let v: ~[&str] = "abc1def2ghi".split(|c: char| c.is_digit()).collect();
932-
/// assert_eq!(v, ~["abc", "def", "ghi"]);
931+
/// let v: Vec<&str> = "abc1def2ghi".split(|c: char| c.is_digit()).collect();
932+
/// assert_eq!(v, vec!["abc", "def", "ghi"]);
933933
///
934-
/// let v: ~[&str] = "lionXXtigerXleopard".split('X').collect();
935-
/// assert_eq!(v, ~["lion", "", "tiger", "leopard"]);
934+
/// let v: Vec<&str> = "lionXXtigerXleopard".split('X').collect();
935+
/// assert_eq!(v, vec!["lion", "", "tiger", "leopard"]);
936936
/// ```
937937
fn split<Sep: CharEq>(&self, sep: Sep) -> CharSplits<'a, Sep>;
938938

@@ -943,14 +943,14 @@ pub trait StrSlice<'a> {
943943
/// # Example
944944
///
945945
/// ```rust
946-
/// let v: ~[&str] = "Mary had a little lambda".splitn(' ', 2).collect();
947-
/// assert_eq!(v, ~["Mary", "had", "a little lambda"]);
946+
/// let v: Vec<&str> = "Mary had a little lambda".splitn(' ', 2).collect();
947+
/// assert_eq!(v, vec!["Mary", "had", "a little lambda"]);
948948
///
949-
/// let v: ~[&str] = "abc1def2ghi".splitn(|c: char| c.is_digit(), 1).collect();
950-
/// assert_eq!(v, ~["abc", "def2ghi"]);
949+
/// let v: Vec<&str> = "abc1def2ghi".splitn(|c: char| c.is_digit(), 1).collect();
950+
/// assert_eq!(v, vec!["abc", "def2ghi"]);
951951
///
952-
/// let v: ~[&str] = "lionXXtigerXleopard".splitn('X', 2).collect();
953-
/// assert_eq!(v, ~["lion", "", "tigerXleopard"]);
952+
/// let v: Vec<&str> = "lionXXtigerXleopard".splitn('X', 2).collect();
953+
/// assert_eq!(v, vec!["lion", "", "tigerXleopard"]);
954954
/// ```
955955
fn splitn<Sep: CharEq>(&self, sep: Sep, count: uint) -> CharSplitsN<'a, Sep>;
956956

@@ -963,20 +963,20 @@ pub trait StrSlice<'a> {
963963
/// # Example
964964
///
965965
/// ```rust
966-
/// let v: ~[&str] = "A.B.".split_terminator('.').collect();
967-
/// assert_eq!(v, ~["A", "B"]);
966+
/// let v: Vec<&str> = "A.B.".split_terminator('.').collect();
967+
/// assert_eq!(v, vec!["A", "B"]);
968968
///
969-
/// let v: ~[&str] = "A..B..".split_terminator('.').collect();
970-
/// assert_eq!(v, ~["A", "", "B", ""]);
969+
/// let v: Vec<&str> = "A..B..".split_terminator('.').collect();
970+
/// assert_eq!(v, vec!["A", "", "B", ""]);
971971
///
972-
/// let v: ~[&str] = "Mary had a little lamb".split(' ').rev().collect();
973-
/// assert_eq!(v, ~["lamb", "little", "a", "had", "Mary"]);
972+
/// let v: Vec<&str> = "Mary had a little lamb".split(' ').rev().collect();
973+
/// assert_eq!(v, vec!["lamb", "little", "a", "had", "Mary"]);
974974
///
975-
/// let v: ~[&str] = "abc1def2ghi".split(|c: char| c.is_digit()).rev().collect();
976-
/// assert_eq!(v, ~["ghi", "def", "abc"]);
975+
/// let v: Vec<&str> = "abc1def2ghi".split(|c: char| c.is_digit()).rev().collect();
976+
/// assert_eq!(v, vec!["ghi", "def", "abc"]);
977977
///
978-
/// let v: ~[&str] = "lionXXtigerXleopard".split('X').rev().collect();
979-
/// assert_eq!(v, ~["leopard", "tiger", "", "lion"]);
978+
/// let v: Vec<&str> = "lionXXtigerXleopard".split('X').rev().collect();
979+
/// assert_eq!(v, vec!["leopard", "tiger", "", "lion"]);
980980
/// ```
981981
fn split_terminator<Sep: CharEq>(&self, sep: Sep) -> CharSplits<'a, Sep>;
982982

@@ -991,14 +991,14 @@ pub trait StrSlice<'a> {
991991
/// # Example
992992
///
993993
/// ```rust
994-
/// let v: ~[&str] = "Mary had a little lamb".rsplitn(' ', 2).collect();
995-
/// assert_eq!(v, ~["lamb", "little", "Mary had a"]);
994+
/// let v: Vec<&str> = "Mary had a little lamb".rsplitn(' ', 2).collect();
995+
/// assert_eq!(v, vec!["lamb", "little", "Mary had a"]);
996996
///
997-
/// let v: ~[&str] = "abc1def2ghi".rsplitn(|c: char| c.is_digit(), 1).collect();
998-
/// assert_eq!(v, ~["ghi", "abc1def"]);
997+
/// let v: Vec<&str> = "abc1def2ghi".rsplitn(|c: char| c.is_digit(), 1).collect();
998+
/// assert_eq!(v, vec!["ghi", "abc1def"]);
999999
///
1000-
/// let v: ~[&str] = "lionXXtigerXleopard".rsplitn('X', 2).collect();
1001-
/// assert_eq!(v, ~["leopard", "tiger", "lionX"]);
1000+
/// let v: Vec<&str> = "lionXXtigerXleopard".rsplitn('X', 2).collect();
1001+
/// assert_eq!(v, vec!["leopard", "tiger", "lionX"]);
10021002
/// ```
10031003
fn rsplitn<Sep: CharEq>(&self, sep: Sep, count: uint) -> CharSplitsN<'a, Sep>;
10041004

@@ -1013,14 +1013,14 @@ pub trait StrSlice<'a> {
10131013
/// # Example
10141014
///
10151015
/// ```rust
1016-
/// let v: ~[(uint, uint)] = "abcXXXabcYYYabc".match_indices("abc").collect();
1017-
/// assert_eq!(v, ~[(0,3), (6,9), (12,15)]);
1016+
/// let v: Vec<(uint, uint)> = "abcXXXabcYYYabc".match_indices("abc").collect();
1017+
/// assert_eq!(v, vec![(0,3), (6,9), (12,15)]);
10181018
///
1019-
/// let v: ~[(uint, uint)] = "1abcabc2".match_indices("abc").collect();
1020-
/// assert_eq!(v, ~[(1,4), (4,7)]);
1019+
/// let v: Vec<(uint, uint)> = "1abcabc2".match_indices("abc").collect();
1020+
/// assert_eq!(v, vec![(1,4), (4,7)]);
10211021
///
1022-
/// let v: ~[(uint, uint)] = "ababa".match_indices("aba").collect();
1023-
/// assert_eq!(v, ~[(0, 3)]); // only the first `aba`
1022+
/// let v: Vec<(uint, uint)> = "ababa".match_indices("aba").collect();
1023+
/// assert_eq!(v, vec![(0, 3)]); // only the first `aba`
10241024
/// ```
10251025
fn match_indices(&self, sep: &'a str) -> MatchIndices<'a>;
10261026

@@ -1029,11 +1029,11 @@ pub trait StrSlice<'a> {
10291029
/// # Example
10301030
///
10311031
/// ```rust
1032-
/// let v: ~[&str] = "abcXXXabcYYYabc".split_str("abc").collect();
1033-
/// assert_eq!(v, ~["", "XXX", "YYY", ""]);
1032+
/// let v: Vec<&str> = "abcXXXabcYYYabc".split_str("abc").collect();
1033+
/// assert_eq!(v, vec!["", "XXX", "YYY", ""]);
10341034
///
1035-
/// let v: ~[&str] = "1abcabc2".split_str("abc").collect();
1036-
/// assert_eq!(v, ~["1", "", "2"]);
1035+
/// let v: Vec<&str> = "1abcabc2".split_str("abc").collect();
1036+
/// assert_eq!(v, vec!["1", "", "2"]);
10371037
/// ```
10381038
fn split_str(&self, &'a str) -> StrSplits<'a>;
10391039

@@ -1045,8 +1045,8 @@ pub trait StrSlice<'a> {
10451045
///
10461046
/// ```rust
10471047
/// let four_lines = "foo\nbar\n\nbaz\n";
1048-
/// let v: ~[&str] = four_lines.lines().collect();
1049-
/// assert_eq!(v, ~["foo", "bar", "", "baz"]);
1048+
/// let v: Vec<&str> = four_lines.lines().collect();
1049+
/// assert_eq!(v, vec!["foo", "bar", "", "baz"]);
10501050
/// ```
10511051
fn lines(&self) -> CharSplits<'a, char>;
10521052

@@ -1058,8 +1058,8 @@ pub trait StrSlice<'a> {
10581058
///
10591059
/// ```rust
10601060
/// let four_lines = "foo\r\nbar\n\r\nbaz\n";
1061-
/// let v: ~[&str] = four_lines.lines_any().collect();
1062-
/// assert_eq!(v, ~["foo", "bar", "", "baz"]);
1061+
/// let v: Vec<&str> = four_lines.lines_any().collect();
1062+
/// assert_eq!(v, vec!["foo", "bar", "", "baz"]);
10631063
/// ```
10641064
fn lines_any(&self) -> AnyLines<'a>;
10651065

@@ -1071,8 +1071,8 @@ pub trait StrSlice<'a> {
10711071
///
10721072
/// ```rust
10731073
/// let some_words = " Mary had\ta little \n\t lamb";
1074-
/// let v: ~[&str] = some_words.words().collect();
1075-
/// assert_eq!(v, ~["Mary", "had", "a", "little", "lamb"]);
1074+
/// let v: Vec<&str> = some_words.words().collect();
1075+
/// assert_eq!(v, vec!["Mary", "had", "a", "little", "lamb"]);
10761076
/// ```
10771077
fn words(&self) -> Words<'a>;
10781078

@@ -1469,7 +1469,8 @@ pub trait StrSlice<'a> {
14691469
///
14701470
/// ```rust
14711471
/// let string = "a\nb\nc";
1472-
/// let lines: ~[&str] = string.lines().collect();
1472+
/// let lines: Vec<&str> = string.lines().collect();
1473+
/// let lines = lines.as_slice();
14731474
///
14741475
/// assert!(string.subslice_offset(lines[0]) == 0); // &"a"
14751476
/// assert!(string.subslice_offset(lines[1]) == 2); // &"b"

branches/try2/src/libgetopts/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
//! fn main() {
5252
//! let args = os::args();
5353
//!
54-
//! let program = args[0].clone();
54+
//! let program = args.get(0).clone();
5555
//!
5656
//! let opts = [
5757
//! optopt("o", "", "set output file name", "NAME"),

branches/try2/src/libserialize/json.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,14 +166,14 @@ use serialize::{json, Encodable, Decodable};
166166
pub struct TestStruct1 {
167167
data_int: u8,
168168
data_str: ~str,
169-
data_vector: ~[u8],
169+
data_vector: Vec<u8>,
170170
}
171171
172172
// To serialize use the `json::str_encode` to encode an object in a string.
173173
// It calls the generated `Encodable` impl.
174174
fn main() {
175175
let to_encode_object = TestStruct1
176-
{data_int: 1, data_str:"toto".to_owned(), data_vector:~[2,3,4,5]};
176+
{data_int: 1, data_str:"toto".to_owned(), data_vector:vec![2,3,4,5]};
177177
let encoded_str: ~str = json::Encoder::str_encode(&to_encode_object);
178178
179179
// To deserialize use the `json::from_str` and `json::Decoder`
@@ -201,7 +201,7 @@ use collections::TreeMap;
201201
pub struct TestStruct1 {
202202
data_int: u8,
203203
data_str: ~str,
204-
data_vector: ~[u8],
204+
data_vector: Vec<u8>,
205205
}
206206
207207
impl ToJson for TestStruct1 {
@@ -218,7 +218,7 @@ fn main() {
218218
// Serialization using our impl of to_json
219219
220220
let test2: TestStruct1 = TestStruct1 {data_int: 1, data_str:"toto".to_owned(),
221-
data_vector:~[2,3,4,5]};
221+
data_vector:vec![2,3,4,5]};
222222
let tjson: json::Json = test2.to_json();
223223
let json_str: ~str = tjson.to_str();
224224

branches/try2/src/libstd/io/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ Some examples of obvious things you might want to do
7676
7777
let path = Path::new("message.txt");
7878
let mut file = BufferedReader::new(File::open(&path));
79-
let lines: ~[~str] = file.lines().map(|x| x.unwrap()).collect();
79+
let lines: Vec<~str> = file.lines().map(|x| x.unwrap()).collect();
8080
```
8181
8282
* Make a simple TCP client connection and request

0 commit comments

Comments
 (0)