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: src/doc/complement-cheatsheet.md
+28-12
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`](http://static.rust-lang.org/doc/master/std/to_str/trait.ToStr.html).
7
+
Use [`ToStr`](../std/to_str/trait.ToStr.html).
8
8
9
9
~~~
10
10
let x: int = 42;
@@ -13,7 +13,8 @@ let y: StrBuf = x.to_str().to_strbuf();
13
13
14
14
**String to int**
15
15
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).
16
+
Use [`FromStr`](../std/from_str/trait.FromStr.html), and its helper function,
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).
38
+
Use [`FromStrRadix`](../std/num/trait.FromStrRadix.html), and its helper
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).
50
+
To return a Borrowed String Slice (&str) use the str helper function
51
+
[`from_utf8`](../std/str/fn.from_utf8.html).
49
52
50
53
~~~
51
54
use std::str;
@@ -55,7 +58,8 @@ let x: Option<&str> = str::from_utf8(bytes);
55
58
let y: &str = x.unwrap();
56
59
~~~
57
60
58
-
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).
61
+
To return an Owned String (StrBuf) use the str helper function
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.
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.
69
76
70
77
~~~
71
78
use std::str;
@@ -78,7 +85,13 @@ let y = str::from_utf8_lossy(x);
78
85
79
86
## How do I read from a file?
80
87
81
-
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.
@@ -91,7 +104,7 @@ let reader : File = File::open(&path).unwrap_or_else(on_error);
91
104
92
105
## How do I iterate over the lines in a file?
93
106
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).
107
+
Use the [`lines`](../std/io/trait.Buffer.html#method.lines) method on a [`BufferedReader`](../std/io/buffered/struct.BufferedReader.html).
95
108
96
109
~~~
97
110
use std::io::BufferedReader;
@@ -109,7 +122,7 @@ for line in reader.lines() {
109
122
110
123
## How do I search for a substring?
111
124
112
-
Use the [`find_str`](http://static.rust-lang.org/doc/master/std/str/trait.StrSlice.html#tymethod.find_str) method.
125
+
Use the [`find_str`](../std/str/trait.StrSlice.html#tymethod.find_str) method.
113
126
114
127
~~~
115
128
let str = "Hello, this is some random string";
@@ -120,7 +133,7 @@ let index: Option<uint> = str.find_str("rand");
120
133
121
134
## How do I get the length of a vector?
122
135
123
-
The [`Container`](http://static.rust-lang.org/doc/master/std/container/trait.Container.html) trait provides the `len` method.
136
+
The [`Container`](../std/container/trait.Container.html) trait provides the `len` method.
Use the [`iter`](http://static.rust-lang.org/doc/master/std/vec/trait.ImmutableVector.html#tymethod.iter) method.
148
+
Use the [`iter`](../std/vec/trait.ImmutableVector.html#tymethod.iter) method.
136
149
137
150
~~~
138
151
let values: ~[int] = ~[1, 2, 3, 4, 5];
@@ -141,7 +154,10 @@ for value in values.iter() { // value: &int
141
154
}
142
155
~~~
143
156
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.)
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
0 commit comments