Skip to content

Commit 899ffcf

Browse files
committed
Intpocalypse, book edition.
Fix all usage of int/uint/i/u in the book.
1 parent 078bd49 commit 899ffcf

13 files changed

+187
-185
lines changed

src/doc/trpl/ffi.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,11 @@ pub fn compress(src: &[u8]) -> Vec<u8> {
116116
let psrc = src.as_ptr();
117117
118118
let mut dstlen = snappy_max_compressed_length(srclen);
119-
let mut dst = Vec::with_capacity(dstlen as uint);
119+
let mut dst = Vec::with_capacity(dstlen as usize);
120120
let pdst = dst.as_mut_ptr();
121121
122122
snappy_compress(psrc, srclen, pdst, &mut dstlen);
123-
dst.set_len(dstlen as uint);
123+
dst.set_len(dstlen as usize);
124124
dst
125125
}
126126
}
@@ -148,11 +148,11 @@ pub fn uncompress(src: &[u8]) -> Option<Vec<u8>> {
148148
let mut dstlen: size_t = 0;
149149
snappy_uncompressed_length(psrc, srclen, &mut dstlen);
150150
151-
let mut dst = Vec::with_capacity(dstlen as uint);
151+
let mut dst = Vec::with_capacity(dstlen as usize);
152152
let pdst = dst.as_mut_ptr();
153153
154154
if snappy_uncompress(psrc, srclen, pdst, &mut dstlen) == 0 {
155-
dst.set_len(dstlen as uint);
155+
dst.set_len(dstlen as usize);
156156
Some(dst)
157157
} else {
158158
None // SNAPPY_INVALID_INPUT

src/doc/trpl/generics.md

+10-10
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ multiple types of arguments. For example, remember our `OptionalInt` type?
55

66
```{rust}
77
enum OptionalInt {
8-
Value(int),
8+
Value(i32),
99
Missing,
1010
}
1111
```
@@ -40,26 +40,26 @@ we substitute that type for the same type used in the generic. Here's an
4040
example of using `Option<T>`, with some extra type annotations:
4141

4242
```{rust}
43-
let x: Option<int> = Some(5i);
43+
let x: Option<i32> = Some(5);
4444
```
4545

46-
In the type declaration, we say `Option<int>`. Note how similar this looks to
47-
`Option<T>`. So, in this particular `Option`, `T` has the value of `int`. On
48-
the right-hand side of the binding, we do make a `Some(T)`, where `T` is `5i`.
49-
Since that's an `int`, the two sides match, and Rust is happy. If they didn't
46+
In the type declaration, we say `Option<i32>`. Note how similar this looks to
47+
`Option<T>`. So, in this particular `Option`, `T` has the value of `i32`. On
48+
the right-hand side of the binding, we do make a `Some(T)`, where `T` is `5`.
49+
Since that's an `i32`, the two sides match, and Rust is happy. If they didn't
5050
match, we'd get an error:
5151

5252
```{rust,ignore}
53-
let x: Option<f64> = Some(5i);
54-
// error: mismatched types: expected `core::option::Option<f64>`
55-
// but found `core::option::Option<int>` (expected f64 but found int)
53+
let x: Option<f64> = Some(5);
54+
// error: mismatched types: expected `core::option::Option<f64>`,
55+
// found `core::option::Option<_>` (expected f64 but found integral variable)
5656
```
5757

5858
That doesn't mean we can't make `Option<T>`s that hold an `f64`! They just have to
5959
match up:
6060

6161
```{rust}
62-
let x: Option<int> = Some(5i);
62+
let x: Option<i32> = Some(5);
6363
let y: Option<f64> = Some(5.0f64);
6464
```
6565

src/doc/trpl/iterators.md

+37-37
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Let's talk about loops.
55
Remember Rust's `for` loop? Here's an example:
66

77
```{rust}
8-
for x in range(0i, 10i) {
8+
for x in range(0, 10) {
99
println!("{}", x);
1010
}
1111
```
@@ -17,7 +17,7 @@ call the `.next()` method on repeatedly, and it gives us a sequence of things.
1717
Like this:
1818

1919
```{rust}
20-
let mut range = range(0i, 10i);
20+
let mut range = range(0, 10);
2121
2222
loop {
2323
match range.next() {
@@ -32,8 +32,8 @@ loop {
3232
We make a mutable binding to the return value of `range`, which is our iterator.
3333
We then `loop`, with an inner `match`. This `match` is used on the result of
3434
`range.next()`, which gives us a reference to the next value of the iterator.
35-
`next` returns an `Option<int>`, in this case, which will be `Some(int)` when
36-
we have a value and `None` once we run out. If we get `Some(int)`, we print it
35+
`next` returns an `Option<i32>`, in this case, which will be `Some(i32)` when
36+
we have a value and `None` once we run out. If we get `Some(i32)`, we print it
3737
out, and if we get `None`, we `break` out of the loop.
3838

3939
This code sample is basically the same as our `for` loop version. The `for`
@@ -50,9 +50,9 @@ primitive. For example, if you needed to iterate over the contents of
5050
a vector, you may be tempted to write this:
5151

5252
```{rust}
53-
let nums = vec![1i, 2i, 3i];
53+
let nums = vec![1, 2, 3];
5454
55-
for i in range(0u, nums.len()) {
55+
for i in range(0, nums.len()) {
5656
println!("{}", nums[i]);
5757
}
5858
```
@@ -62,7 +62,7 @@ vectors returns an iterator which iterates through a reference to each element
6262
of the vector in turn. So write this:
6363

6464
```{rust}
65-
let nums = vec![1i, 2i, 3i];
65+
let nums = vec![1, 2, 3];
6666
6767
for num in nums.iter() {
6868
println!("{}", num);
@@ -79,12 +79,12 @@ very common with iterators: we can ignore unnecessary bounds checks, but still
7979
know that we're safe.
8080

8181
There's another detail here that's not 100% clear because of how `println!`
82-
works. `num` is actually of type `&int`. That is, it's a reference to an `int`,
83-
not an `int` itself. `println!` handles the dereferencing for us, so we don't
82+
works. `num` is actually of type `&i32`. That is, it's a reference to an `i32`,
83+
not an `i32` itself. `println!` handles the dereferencing for us, so we don't
8484
see it. This code works fine too:
8585

8686
```{rust}
87-
let nums = vec![1i, 2i, 3i];
87+
let nums = vec![1, 2, 3];
8888
8989
for num in nums.iter() {
9090
println!("{}", *num);
@@ -118,7 +118,7 @@ The most common consumer is `collect()`. This code doesn't quite compile,
118118
but it shows the intention:
119119

120120
```{rust,ignore}
121-
let one_to_one_hundred = range(1i, 101i).collect();
121+
let one_to_one_hundred = range(1, 101).collect();
122122
```
123123

124124
As you can see, we call `collect()` on our iterator. `collect()` takes
@@ -128,7 +128,7 @@ type of things you want to collect, and so you need to let it know.
128128
Here's the version that does compile:
129129

130130
```{rust}
131-
let one_to_one_hundred = range(1i, 101i).collect::<Vec<int>>();
131+
let one_to_one_hundred = range(1, 101).collect::<Vec<i32>>();
132132
```
133133

134134
If you remember, the `::<>` syntax allows us to give a type hint,
@@ -138,7 +138,7 @@ and so we tell it that we want a vector of integers.
138138
is one:
139139

140140
```{rust}
141-
let greater_than_forty_two = range(0i, 100i)
141+
let greater_than_forty_two = range(0, 100)
142142
.find(|x| *x > 42);
143143
144144
match greater_than_forty_two {
@@ -155,8 +155,8 @@ element, `find` returns an `Option` rather than the element itself.
155155
Another important consumer is `fold`. Here's what it looks like:
156156

157157
```{rust}
158-
let sum = range(1i, 4i)
159-
.fold(0i, |sum, x| sum + x);
158+
let sum = range(1, 4)
159+
.fold(0, |sum, x| sum + x);
160160
```
161161

162162
`fold()` is a consumer that looks like this:
@@ -172,24 +172,24 @@ in this iterator:
172172

173173
| base | accumulator | element | closure result |
174174
|------|-------------|---------|----------------|
175-
| 0i | 0i | 1i | 1i |
176-
| 0i | 1i | 2i | 3i |
177-
| 0i | 3i | 3i | 6i |
175+
| 0 | 0 | 1 | 1 |
176+
| 0 | 1 | 2 | 3 |
177+
| 0 | 3 | 3 | 6 |
178178

179179
We called `fold()` with these arguments:
180180

181181
```{rust}
182-
# range(1i, 4i)
183-
.fold(0i, |sum, x| sum + x);
182+
# range(1, 4)
183+
.fold(0, |sum, x| sum + x);
184184
```
185185

186-
So, `0i` is our base, `sum` is our accumulator, and `x` is our element. On the
187-
first iteration, we set `sum` to `0i`, and `x` is the first element of `nums`,
188-
`1i`. We then add `sum` and `x`, which gives us `0i + 1i = 1i`. On the second
186+
So, `0` is our base, `sum` is our accumulator, and `x` is our element. On the
187+
first iteration, we set `sum` to `0`, and `x` is the first element of `nums`,
188+
`1`. We then add `sum` and `x`, which gives us `0 + 1 = 1`. On the second
189189
iteration, that value becomes our accumulator, `sum`, and the element is
190-
the second element of the array, `2i`. `1i + 2i = 3i`, and so that becomes
190+
the second element of the array, `2`. `1 + 2 = 3`, and so that becomes
191191
the value of the accumulator for the last iteration. On that iteration,
192-
`x` is the last element, `3i`, and `3i + 3i = 6i`, which is our final
192+
`x` is the last element, `3`, and `3 + 3 = 6`, which is our final
193193
result for our sum. `1 + 2 + 3 = 6`, and that's the result we got.
194194

195195
Whew. `fold` can be a bit strange the first few times you see it, but once it
@@ -210,14 +210,14 @@ This code, for example, does not actually generate the numbers
210210
`1-100`, and just creates a value that represents the sequence:
211211

212212
```{rust}
213-
let nums = range(1i, 100i);
213+
let nums = range(1, 100);
214214
```
215215

216216
Since we didn't do anything with the range, it didn't generate the sequence.
217217
Let's add the consumer:
218218

219219
```{rust}
220-
let nums = range(1i, 100i).collect::<Vec<int>>();
220+
let nums = range(1, 100).collect::<Vec<i32>>();
221221
```
222222

223223
Now, `collect()` will require that `range()` give it some numbers, and so
@@ -228,7 +228,7 @@ which you've used before. `iter()` can turn a vector into a simple iterator
228228
that gives you each element in turn:
229229

230230
```{rust}
231-
let nums = [1i, 2i, 3i];
231+
let nums = [1, 2, 3];
232232
233233
for num in nums.iter() {
234234
println!("{}", num);
@@ -239,12 +239,12 @@ These two basic iterators should serve you well. There are some more
239239
advanced iterators, including ones that are infinite. Like `count`:
240240

241241
```{rust}
242-
std::iter::count(1i, 5i);
242+
std::iter::count(1, 5);
243243
```
244244

245245
This iterator counts up from one, adding five each time. It will give
246246
you a new integer every time, forever (well, technically, until it reaches the
247-
maximum number representable by an `int`). But since iterators are lazy,
247+
maximum number representable by an `i32`). But since iterators are lazy,
248248
that's okay! You probably don't want to use `collect()` on it, though...
249249

250250
That's enough about iterators. Iterator adapters are the last concept
@@ -256,7 +256,7 @@ we need to talk about with regards to iterators. Let's get to it!
256256
a new iterator. The simplest one is called `map`:
257257

258258
```{rust,ignore}
259-
range(1i, 100i).map(|x| x + 1i);
259+
range(1, 100).map(|x| x + 1);
260260
```
261261

262262
`map` is called upon another iterator, and produces a new iterator where each
@@ -267,15 +267,15 @@ compile the example, you'll get a warning:
267267
```{notrust,ignore}
268268
warning: unused result which must be used: iterator adaptors are lazy and
269269
do nothing unless consumed, #[warn(unused_must_use)] on by default
270-
range(1i, 100i).map(|x| x + 1i);
270+
range(1, 100).map(|x| x + 1);
271271
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
272272
```
273273

274274
Laziness strikes again! That closure will never execute. This example
275275
doesn't print any numbers:
276276

277277
```{rust,ignore}
278-
range(1i, 100i).map(|x| println!("{}", x));
278+
range(1, 100).map(|x| println!("{}", x));
279279
```
280280

281281
If you are trying to execute a closure on an iterator for its side effects,
@@ -287,7 +287,7 @@ has no side effect on the original iterator. Let's try it out with our infinite
287287
iterator from before, `count()`:
288288

289289
```{rust}
290-
for i in std::iter::count(1i, 5i).take(5) {
290+
for i in std::iter::count(1, 5).take(5) {
291291
println!("{}", i);
292292
}
293293
```
@@ -307,7 +307,7 @@ returns `true` or `false`. The new iterator `filter()` produces
307307
only the elements that that closure returns `true` for:
308308

309309
```{rust}
310-
for i in range(1i, 100i).filter(|&x| x % 2 == 0) {
310+
for i in range(1, 100).filter(|&x| x % 2 == 0) {
311311
println!("{}", i);
312312
}
313313
```
@@ -322,11 +322,11 @@ You can chain all three things together: start with an iterator, adapt it
322322
a few times, and then consume the result. Check it out:
323323

324324
```{rust}
325-
range(1i, 1000i)
325+
range(1, 1000)
326326
.filter(|&x| x % 2 == 0)
327327
.filter(|&x| x % 3 == 0)
328328
.take(5)
329-
.collect::<Vec<int>>();
329+
.collect::<Vec<i32>>();
330330
```
331331

332332
This will give you a vector containing `6`, `12`, `18`, `24`, and `30`.

src/doc/trpl/looping.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ The other kind of looping construct in Rust is the `while` loop. It looks like
5454
this:
5555

5656
```{rust}
57-
let mut x = 5u32; // mut x: u32
57+
let mut x = 5; // mut x: u32
5858
let mut done = false; // mut done: bool
5959
6060
while !done {
@@ -91,7 +91,7 @@ can do with safety and code generation, so you should always prefer
9191
Let's take a look at that `while` loop we had earlier:
9292

9393
```{rust}
94-
let mut x = 5u32;
94+
let mut x = 5;
9595
let mut done = false;
9696
9797
while !done {
@@ -108,7 +108,7 @@ modifying iteration: `break` and `continue`.
108108
In this case, we can write the loop in a better way with `break`:
109109

110110
```{rust}
111-
let mut x = 5u32;
111+
let mut x = 5;
112112
113113
loop {
114114
x += x - 3;

0 commit comments

Comments
 (0)