Skip to content

Commit c47f4d2

Browse files
committed
---
yaml --- r: 128733 b: refs/heads/try c: c1eaafe h: refs/heads/master i: 128731: 0bad11c v: v3
1 parent 49f2546 commit c47f4d2

File tree

20 files changed

+391
-49
lines changed

20 files changed

+391
-49
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: 07d86b46a949a94223da714e35b343243e4ecce4
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: a86d9ad15e339ab343a12513f9c90556f677b9ca
5-
refs/heads/try: 04233a1675272d4a21440943f1441b586cdf0afd
5+
refs/heads/try: c1eaafe8ab2114dd10d87a4983e1263c844f782f
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c

branches/try/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ documentation.
3232

3333
To build from the [tarball] do:
3434

35-
$ curl -O http://static.rust-lang.org/dist/rust-nightly.tar.gz
35+
$ curl -O https://static.rust-lang.org/dist/rust-nightly.tar.gz
3636
$ tar -xzf rust-nightly.tar.gz
3737
$ cd rust-nightly
3838

@@ -75,7 +75,7 @@ To easily build on windows we can use [MSYS2](http://sourceforge.net/projects/ms
7575
$ make && make install
7676

7777
[repo]: https://github.com/rust-lang/rust
78-
[tarball]: http://static.rust-lang.org/dist/rust-nightly.tar.gz
78+
[tarball]: https://static.rust-lang.org/dist/rust-nightly.tar.gz
7979
[tutorial]: http://doc.rust-lang.org/tutorial.html
8080

8181
## Notes

branches/try/src/doc/guide.md

Lines changed: 74 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,21 @@ Linux or a Mac, all you need to do is this (note that you don't need to type
3232
in the `$`s, they just indicate the start of each command):
3333

3434
```{ignore}
35-
$ curl -s http://www.rust-lang.org/rustup.sh | sudo sh
35+
$ curl -s https://static.rust-lang.org/rustup.sh | sudo sh
3636
```
3737

3838
(If you're concerned about `curl | sudo sh`, please keep reading. Disclaimer
3939
below.)
4040

4141
If you're on Windows, please [download this .exe and run
42-
it](http://static.rust-lang.org/dist/rust-nightly-install.exe).
42+
it](https://static.rust-lang.org/dist/rust-nightly-install.exe).
4343

4444
If you decide you don't want Rust anymore, we'll be a bit sad, but that's okay.
4545
Not every programming language is great for everyone. Just pass an argument to
4646
the script:
4747

4848
```{ignore}
49-
$ curl -s http://www.rust-lang.org/rustup.sh | sudo sh -s -- --uninstall
49+
$ curl -s https://static.rust-lang.org/rustup.sh | sudo sh -s -- --uninstall
5050
```
5151

5252
If you used the Windows installer, just re-run the `.exe` and it will give you
@@ -1341,7 +1341,7 @@ computer science: naming things, cache invalidation, and off-by-one errors."
13411341
The joke, of course, being that the setup says "two hard problems" but then
13421342
lists three things. This happens quite a bit with "C style" `for` loops.
13431343

1344-
We'll talk more about `for` when we cover **vector**s, later in the Guide.
1344+
We'll talk more about `for` when we cover **iterator**s, later in the Guide.
13451345

13461346
## `while`
13471347

@@ -1427,11 +1427,6 @@ for x in range(0i, 10i) {
14271427

14281428
Both `continue` and `break` are valid in both kinds of loops.
14291429

1430-
We have now learned all of the most basic Rust concepts. We're ready to start
1431-
building our guessing game, but we need to know how to do one last thing first:
1432-
get input from the keyboard. You can't have a guessing game without the ability
1433-
to guess!
1434-
14351430
# Strings
14361431

14371432
Strings are an important concept for any programmer to master. Rust's string
@@ -1512,6 +1507,76 @@ low-level details matter, they really matter. Just remember that `String`s
15121507
allocate memory and control their data, while `&str`s are a reference to
15131508
another string, and you'll be all set.
15141509

1510+
# Vectors
1511+
1512+
Like many programming languages, Rust has a list type for when you want a list
1513+
of things. But similar to strings, Rust has different types to represent this
1514+
idea: `Vec<T>` (a 'vector'), `[T, .. N]` (an 'array'), and `&[T]` (a 'slice').
1515+
Whew!
1516+
1517+
Vectors are similar to `String`s: they have a dynamic length, and they
1518+
allocate enough memory to fit. You can create a vector with the `vec!` macro:
1519+
1520+
```{rust}
1521+
let nums = vec![1i, 2i, 3i];
1522+
```
1523+
1524+
Notice that unlike the `println!` macro we've used in the past, we use square
1525+
brackets (`[]`) with `vec!`. Rust allows you to use either in either situation,
1526+
this is just convention.
1527+
1528+
You can create an array with just square brackets:
1529+
1530+
```{rust}
1531+
let nums = [1i, 2i, 3i];
1532+
```
1533+
1534+
So what's the difference? An array has a fixed size, so you can't add or
1535+
subtract elements:
1536+
1537+
```{rust,ignore}
1538+
let mut nums = vec![1i, 2i, 3i];
1539+
nums.push(4i); // works
1540+
1541+
let mut nums = [1i, 2i, 3i];
1542+
nums.push(4i); // error: type `[int, .. 3]` does not implement any method
1543+
// in scope named `push`
1544+
```
1545+
1546+
The `push()` method lets you append a value to the end of the vector. But
1547+
since arrays have fixed sizes, adding an element doesn't make any sense.
1548+
You can see how it has the exact type in the error message: `[int, .. 3]`.
1549+
An array of `int`s, with length 3.
1550+
1551+
Similar to `&str`, a slice is a reference to another array. We can get a
1552+
slice from a vector by using the `as_slice()` method:
1553+
1554+
```{rust}
1555+
let vec = vec![1i, 2i, 3i];
1556+
let slice = vec.as_slice();
1557+
```
1558+
1559+
All three types implement an `iter()` method, which returns an iterator. We'll
1560+
talk more about the details of iterators later, but for now, the `iter()` method
1561+
allows you to write a `for` loop that prints out the contents of a vector, array,
1562+
or slice:
1563+
1564+
```{rust}
1565+
let vec = vec![1i, 2i, 3i];
1566+
1567+
for i in vec.iter() {
1568+
println!("{}", i);
1569+
}
1570+
```
1571+
1572+
This code will print each number in order, on its own line.
1573+
1574+
There's a whole lot more to vectors, but that's enough to get started. We have
1575+
now learned all of the most basic Rust concepts. We're ready to start building
1576+
our guessing game, but we need to know how to do one last thing first: get
1577+
input from the keyboard. You can't have a guessing game without the ability to
1578+
guess!
1579+
15151580
# Standard Input
15161581

15171582
Getting input from the keyboard is pretty easy, but uses some things

branches/try/src/doc/tutorial.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ If you've fulfilled those prerequisites, something along these lines
114114
should work.
115115

116116
~~~~console
117-
$ curl -O http://static.rust-lang.org/dist/rust-nightly.tar.gz
117+
$ curl -O https://static.rust-lang.org/dist/rust-nightly.tar.gz
118118
$ tar -xzf rust-nightly.tar.gz
119119
$ cd rust-nightly
120120
$ ./configure
@@ -131,8 +131,8 @@ When complete, `make install` will place several programs into
131131
`/usr/local/bin`: `rustc`, the Rust compiler, and `rustdoc`, the
132132
API-documentation tool.
133133

134-
[tarball]: http://static.rust-lang.org/dist/rust-nightly.tar.gz
135-
[win-exe]: http://static.rust-lang.org/dist/rust-nightly-install.exe
134+
[tarball]: https://static.rust-lang.org/dist/rust-nightly.tar.gz
135+
[win-exe]: https://static.rust-lang.org/dist/rust-nightly-install.exe
136136

137137
## Compiling your first program
138138

branches/try/src/etc/snapshot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def scrub(b):
2828
raise Exception("missing env var CFG_SRC_DIR")
2929

3030
snapshotfile = os.path.join(src_dir, "src", "snapshots.txt")
31-
download_url_base = "http://static.rust-lang.org/stage0-snapshots"
31+
download_url_base = "https://static.rust-lang.org/stage0-snapshots"
3232
download_dir_base = "dl"
3333
download_unpack_base = os.path.join(download_dir_base, "unpack")
3434

branches/try/src/libcollections/ringbuf.rs

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ impl<T> RingBuf<T> {
139139
/// # Example
140140
///
141141
/// ```rust
142+
/// #![allow(deprecated)]
143+
///
142144
/// use std::collections::RingBuf;
143145
///
144146
/// let mut buf = RingBuf::new();
@@ -147,6 +149,7 @@ impl<T> RingBuf<T> {
147149
/// buf.push(5);
148150
/// assert_eq!(buf.get(1), &4);
149151
/// ```
152+
#[deprecated = "prefer using indexing, e.g., ringbuf[0]"]
150153
pub fn get<'a>(&'a self, i: uint) -> &'a T {
151154
let idx = self.raw_index(i);
152155
match *self.elts.get(idx) {
@@ -169,7 +172,7 @@ impl<T> RingBuf<T> {
169172
/// buf.push(4);
170173
/// buf.push(5);
171174
/// *buf.get_mut(1) = 7;
172-
/// assert_eq!(buf.get(1), &7);
175+
/// assert_eq!(buf[1], 7);
173176
/// ```
174177
pub fn get_mut<'a>(&'a mut self, i: uint) -> &'a mut T {
175178
let idx = self.raw_index(i);
@@ -195,8 +198,8 @@ impl<T> RingBuf<T> {
195198
/// buf.push(4);
196199
/// buf.push(5);
197200
/// buf.swap(0, 2);
198-
/// assert_eq!(buf.get(0), &5);
199-
/// assert_eq!(buf.get(2), &3);
201+
/// assert_eq!(buf[0], 5);
202+
/// assert_eq!(buf[2], 3);
200203
/// ```
201204
pub fn swap(&mut self, i: uint, j: uint) {
202205
assert!(i < self.len());
@@ -476,6 +479,21 @@ impl<S: Writer, A: Hash<S>> Hash<S> for RingBuf<A> {
476479
}
477480
}
478481

482+
impl<A> Index<uint, A> for RingBuf<A> {
483+
#[inline]
484+
fn index<'a>(&'a self, i: &uint) -> &'a A {
485+
self.get(*i)
486+
}
487+
}
488+
489+
// FIXME(#12825) Indexing will always try IndexMut first and that causes issues.
490+
/*impl<A> IndexMut<uint, A> for RingBuf<A> {
491+
#[inline]
492+
fn index_mut<'a>(&'a mut self, index: &uint) -> &'a mut A {
493+
self.get_mut(*index)
494+
}
495+
}*/
496+
479497
impl<A> FromIterator<A> for RingBuf<A> {
480498
fn from_iter<T: Iterator<A>>(iterator: T) -> RingBuf<A> {
481499
let (lower, _) = iterator.size_hint();
@@ -653,6 +671,25 @@ mod tests {
653671
}
654672
}
655673

674+
#[test]
675+
fn test_index() {
676+
let mut deq = RingBuf::new();
677+
for i in range(1u, 4) {
678+
deq.push_front(i);
679+
}
680+
assert_eq!(deq[1], 2);
681+
}
682+
683+
#[test]
684+
#[should_fail]
685+
fn test_index_out_of_bounds() {
686+
let mut deq = RingBuf::new();
687+
for i in range(1u, 4) {
688+
deq.push_front(i);
689+
}
690+
deq[3];
691+
}
692+
656693
#[bench]
657694
fn bench_new(b: &mut test::Bencher) {
658695
b.iter(|| {

branches/try/src/libcollections/slice.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,28 @@ pub trait ImmutableCloneableVector<T> {
301301

302302
/// Create an iterator that yields every possible permutation of the
303303
/// vector in succession.
304+
///
305+
/// # Example
306+
///
307+
/// ```rust
308+
/// let v = [1i, 2, 3];
309+
/// let mut perms = v.permutations();
310+
///
311+
/// for p in perms {
312+
/// println!("{}", p);
313+
/// }
314+
/// ```
315+
///
316+
/// # Example 2: iterating through permutations one by one.
317+
///
318+
/// ```rust
319+
/// let v = [1i, 2, 3];
320+
/// let mut perms = v.permutations();
321+
///
322+
/// assert_eq!(Some(vec![1i, 2, 3]), perms.next());
323+
/// assert_eq!(Some(vec![1i, 3, 2]), perms.next());
324+
/// assert_eq!(Some(vec![3i, 1, 2]), perms.next());
325+
/// ```
304326
fn permutations(self) -> Permutations<T>;
305327
}
306328

@@ -321,6 +343,7 @@ impl<'a,T:Clone> ImmutableCloneableVector<T> for &'a [T] {
321343
(lefts, rights)
322344
}
323345

346+
/// Returns an iterator over all permutations of a vector.
324347
fn permutations(self) -> Permutations<T> {
325348
Permutations{
326349
swaps: ElementSwaps::new(self.len()),
@@ -567,6 +590,16 @@ pub trait MutableVectorAllocating<'a, T> {
567590
* * src - A mutable vector of `T`
568591
* * start - The index into `src` to start copying from
569592
* * end - The index into `src` to stop copying from
593+
*
594+
* # Example
595+
*
596+
* ```rust
597+
* let mut a = [1i, 2, 3, 4, 5];
598+
* let b = vec![6i, 7, 8];
599+
* let num_moved = a.move_from(b, 0, 3);
600+
* assert_eq!(num_moved, 3);
601+
* assert!(a == [6i, 7, 8, 4, 5]);
602+
* ```
570603
*/
571604
fn move_from(self, src: Vec<T>, start: uint, end: uint) -> uint;
572605
}

0 commit comments

Comments
 (0)