You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: trunk/src/doc/complement-cheatsheet.md
+12-28Lines changed: 12 additions & 28 deletions
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@
4
4
5
5
**Int to string**
6
6
7
-
Use [`ToStr`](../std/to_str/trait.ToStr.html).
7
+
Use [`ToStr`](http://static.rust-lang.org/doc/master/std/to_str/trait.ToStr.html).
8
8
9
9
~~~
10
10
let x: int = 42;
@@ -13,8 +13,7 @@ let y: StrBuf = x.to_str().to_strbuf();
13
13
14
14
**String to int**
15
15
16
-
Use [`FromStr`](../std/from_str/trait.FromStr.html), and its helper function,
17
-
[`from_str`](../std/from_str/fn.from_str.html).
16
+
Use [`FromStr`](http://static.rust-lang.org/doc/master/std/from_str/trait.FromStr.html), and its helper function, [`from_str`](http://static.rust-lang.org/doc/master/std/from_str/fn.from_str.html).
Use [`FromStrRadix`](http://static.rust-lang.org/doc/master/std/num/trait.FromStrRadix.html), and its helper function, [`from_str_radix`](http://static.rust-lang.org/doc/master/std/num/fn.from_str_radix.html).
40
38
41
39
~~~
42
40
use std::num;
@@ -47,8 +45,7 @@ let y: i64 = x.unwrap();
47
45
48
46
**Vector of Bytes to String**
49
47
50
-
To return a Borrowed String Slice (&str) use the str helper function
51
-
[`from_utf8`](../std/str/fn.from_utf8.html).
48
+
To return a Borrowed String Slice (&str) use the str helper function [`from_utf8`](http://static.rust-lang.org/doc/master/std/str/fn.from_utf8.html).
52
49
53
50
~~~
54
51
use std::str;
@@ -58,8 +55,7 @@ let x: Option<&str> = str::from_utf8(bytes);
58
55
let y: &str = x.unwrap();
59
56
~~~
60
57
61
-
To return an Owned String (StrBuf) use the str helper function
To return an Owned String (StrBuf) use the str helper function [`from_utf8_owned`](http://static.rust-lang.org/doc/master/std/str/fn.from_utf8_owned.html).
63
59
64
60
~~~
65
61
use std::str;
@@ -69,10 +65,7 @@ let x: Option<StrBuf> =
69
65
let y: StrBuf = x.unwrap();
70
66
~~~
71
67
72
-
To return a [`MaybeOwned`](../std/str/enum.MaybeOwned.html) use the str helper
73
-
function [`from_utf8_lossy`](../std/str/fn.from_utf8_owned.html).
74
-
This function also replaces non-valid utf-8 sequences with U+FFFD replacement
75
-
character.
68
+
To return a [`MaybeOwned`](http://static.rust-lang.org/doc/master/std/str/enum.MaybeOwned.html) use the str helper function [`from_utf8_lossy`](http://static.rust-lang.org/doc/master/std/str/fn.from_utf8_owned.html). This function also replaces non-valid utf-8 sequences with U+FFFD replacement character.
76
69
77
70
~~~
78
71
use std::str;
@@ -85,13 +78,7 @@ let y = str::from_utf8_lossy(x);
Use [`File::open`](http://static.rust-lang.org/doc/master/std/io/fs/struct.File.html#method.open) to create a [`File`](http://static.rust-lang.org/doc/master/std/io/fs/struct.File.html) struct, which implements the [`Reader`](http://static.rust-lang.org/doc/master/std/io/trait.Reader.html) trait.
95
82
96
83
~~~{.ignore}
97
84
use std::path::Path;
@@ -104,7 +91,7 @@ let reader : File = File::open(&path).unwrap_or_else(on_error);
104
91
105
92
## How do I iterate over the lines in a file?
106
93
107
-
Use the [`lines`](../std/io/trait.Buffer.html#method.lines) method on a [`BufferedReader`](../std/io/buffered/struct.BufferedReader.html).
94
+
Use the [`lines`](http://static.rust-lang.org/doc/master/std/io/trait.Buffer.html#method.lines) method on a [`BufferedReader`](http://static.rust-lang.org/doc/master/std/io/buffered/struct.BufferedReader.html).
108
95
109
96
~~~
110
97
use std::io::BufferedReader;
@@ -122,7 +109,7 @@ for line in reader.lines() {
122
109
123
110
## How do I search for a substring?
124
111
125
-
Use the [`find_str`](../std/str/trait.StrSlice.html#tymethod.find_str) method.
112
+
Use the [`find_str`](http://static.rust-lang.org/doc/master/std/str/trait.StrSlice.html#tymethod.find_str) method.
126
113
127
114
~~~
128
115
let str = "Hello, this is some random string";
@@ -133,7 +120,7 @@ let index: Option<uint> = str.find_str("rand");
133
120
134
121
## How do I get the length of a vector?
135
122
136
-
The [`Container`](../std/container/trait.Container.html) trait provides the `len` method.
123
+
The [`Container`](http://static.rust-lang.org/doc/master/std/container/trait.Container.html) trait provides the `len` method.
Use the [`iter`](../std/vec/trait.ImmutableVector.html#tymethod.iter) method.
135
+
Use the [`iter`](http://static.rust-lang.org/doc/master/std/vec/trait.ImmutableVector.html#tymethod.iter) method.
149
136
150
137
~~~
151
138
let values: ~[int] = ~[1, 2, 3, 4, 5];
@@ -154,10 +141,7 @@ for value in values.iter() { // value: &int
154
141
}
155
142
~~~
156
143
157
-
(See also [`mut_iter`](../std/vec/trait.MutableVector.html#tymethod.mut_iter)
158
-
which yields `&mut int` and
159
-
[`move_iter`](../std/vec/trait.OwnedVector.html#tymethod.move_iter) which yields
160
-
`int` while consuming the `values` vector.)
144
+
(See also [`mut_iter`](http://static.rust-lang.org/doc/master/std/vec/trait.MutableVector.html#tymethod.mut_iter) which yields `&mut int` and [`move_iter`](http://static.rust-lang.org/doc/master/std/vec/trait.OwnedVector.html#tymethod.move_iter) which yields `int` while consuming the `values` vector.)
0 commit comments