4
4
5
5
** Int to string**
6
6
7
- Use [ ` ToStr ` ] ( ../ 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,8 +13,8 @@ let y: String = x.to_str().to_string();
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 ` ] ( std/from_str/trait.FromStr.html ) , and its helper function,
17
+ [ ` from_str ` ] ( std/from_str/fn.from_str.html ) .
18
18
19
19
~~~
20
20
let x: Option<int> = from_str("42");
@@ -35,8 +35,8 @@ let y: String = format!("{:X}", x); // uppercase hexadecimal
35
35
36
36
** String to int, in non-base-10**
37
37
38
- Use [ ` FromStrRadix ` ] ( ../ std/num/trait.FromStrRadix.html) , and its helper
39
- function, [ ` from_str_radix ` ] ( ../ std/num/fn.from_str_radix.html) .
38
+ Use [ ` FromStrRadix ` ] ( std/num/trait.FromStrRadix.html ) , and its helper
39
+ function, [ ` from_str_radix ` ] ( std/num/fn.from_str_radix.html ) .
40
40
41
41
~~~
42
42
use std::num;
@@ -48,7 +48,7 @@ let y: i64 = x.unwrap();
48
48
** Vector of Bytes to String**
49
49
50
50
To return a Borrowed String Slice (&str) use the str helper function
51
- [ ` from_utf8 ` ] ( ../ std/str/fn.from_utf8.html) .
51
+ [ ` from_utf8 ` ] ( std/str/fn.from_utf8.html ) .
52
52
53
53
~~~
54
54
use std::str;
@@ -58,7 +58,7 @@ let x: &str = str::from_utf8(bytes).unwrap();
58
58
~~~
59
59
60
60
To return an Owned String use the str helper function
61
- [ ` from_utf8_owned ` ] ( ../ std/str/fn.from_utf8_owned.html) .
61
+ [ ` from_utf8_owned ` ] ( std/str/fn.from_utf8_owned.html ) .
62
62
63
63
~~~
64
64
use std::str;
@@ -68,8 +68,8 @@ let x: Option<String> =
68
68
let y: String = x.unwrap();
69
69
~~~
70
70
71
- To return a [ ` MaybeOwned ` ] ( ../ std/str/enum .MaybeOwned.html) use the str helper
72
- function [ ` from_utf8_lossy ` ] ( ../ std/str/fn.from_utf8_owned.html) .
71
+ To return a [ ` MaybeOwned ` ] ( std/str/type .MaybeOwned.html ) use the str helper
72
+ function [ ` from_utf8_lossy ` ] ( std/str/fn.from_utf8_owned.html ) .
73
73
This function also replaces non-valid utf-8 sequences with U+FFFD replacement
74
74
character.
75
75
@@ -85,11 +85,11 @@ let y = str::from_utf8_lossy(x);
85
85
## How do I read from a file?
86
86
87
87
Use
88
- [ ` File::open ` ] ( ../ std/io/fs/struct.File.html#method.open)
88
+ [ ` File::open ` ] ( std/io/fs/struct.File.html#method.open )
89
89
to create a
90
- [ ` File ` ] ( ../ std/io/fs/struct.File.html)
90
+ [ ` File ` ] ( std/io/fs/struct.File.html )
91
91
struct, which implements the
92
- [ ` Reader ` ] ( ../ std/io/trait.Reader.html)
92
+ [ ` Reader ` ] ( std/io/trait.Reader.html )
93
93
trait.
94
94
95
95
~~~ {.ignore}
@@ -103,7 +103,8 @@ let reader : File = File::open(&path).unwrap_or_else(on_error);
103
103
104
104
## How do I iterate over the lines in a file?
105
105
106
- Use the [ ` lines ` ] ( ../std/io/trait.Buffer.html#method.lines ) method on a [ ` BufferedReader ` ] ( ../std/io/buffered/struct.BufferedReader.html ) .
106
+ Use the [ ` lines ` ] ( std/io/trait.Buffer.html#method.lines ) method on a
107
+ [ ` BufferedReader ` ] ( std/io/struct.BufferedReader.html ) .
107
108
108
109
~~~
109
110
use std::io::BufferedReader;
@@ -121,7 +122,7 @@ for line in reader.lines() {
121
122
122
123
## How do I search for a substring?
123
124
124
- Use the [ ` find_str ` ] ( ../ std/str/trait.StrSlice.html#tymethod.find_str) method.
125
+ Use the [ ` find_str ` ] ( std/str/trait.StrSlice.html#tymethod.find_str ) method.
125
126
126
127
~~~
127
128
let str = "Hello, this is some random string";
@@ -132,7 +133,7 @@ let index: Option<uint> = str.find_str("rand");
132
133
133
134
## How do I get the length of a vector?
134
135
135
- The [ ` Container ` ] ( ../ std/container/trait.Container.html) trait provides the ` len ` method.
136
+ The [ ` Container ` ] ( std/container/trait.Container.html ) trait provides the ` len ` method.
136
137
137
138
~~~
138
139
let u: Vec<u32> = vec![0, 1, 2];
@@ -144,7 +145,7 @@ println!("u: {}, v: {}, w: {}", u.len(), v.len(), w.len()); // 3, 4, 5
144
145
145
146
## How do I iterate over a vector?
146
147
147
- Use the [ ` iter ` ] ( ../ std/vec /trait.ImmutableVector.html#tymethod.iter) method.
148
+ Use the [ ` iter ` ] ( std/slice /trait.ImmutableVector.html#tymethod.iter ) method.
148
149
149
150
~~~
150
151
let values: Vec<int> = vec![1, 2, 3, 4, 5];
@@ -153,9 +154,9 @@ for value in values.iter() { // value: &int
153
154
}
154
155
~~~
155
156
156
- (See also [ ` mut_iter ` ] ( ../ std/vec /trait.MutableVector.html#tymethod.mut_iter)
157
+ (See also [ ` mut_iter ` ] ( std/slice /trait.MutableVector.html#tymethod.mut_iter )
157
158
which yields ` &mut int ` and
158
- [ ` move_iter ` ] ( ../ std/vec /trait.OwnedVector.html#tymethod.move_iter) which yields
159
+ [ ` move_iter ` ] ( std/slice /trait.OwnedVector.html#tymethod.move_iter ) which yields
159
160
` int ` while consuming the ` values ` vector.)
160
161
161
162
# Type system
0 commit comments