@@ -53,9 +53,8 @@ To return a Borrowed String Slice (&str) use the str helper function
53
53
~~~
54
54
use std::str;
55
55
56
- let bytes = ~[104u8,105u8];
57
- let x: Option<&str> = str::from_utf8(bytes);
58
- let y: &str = x.unwrap();
56
+ let bytes = &[104u8,105u8];
57
+ let x: &str = str::from_utf8(bytes).unwrap();
59
58
~~~
60
59
61
60
To return an Owned String use the str helper function
@@ -136,7 +135,7 @@ let index: Option<uint> = str.find_str("rand");
136
135
The [ ` Container ` ] ( ../std/container/trait.Container.html ) trait provides the ` len ` method.
137
136
138
137
~~~
139
- let u: ~[ u32] = ~ [0, 1, 2];
138
+ let u: Vec< u32> = vec! [0, 1, 2];
140
139
let v: &[u32] = &[0, 1, 2, 3];
141
140
let w: [u32, .. 5] = [0, 1, 2, 3, 4];
142
141
@@ -148,7 +147,7 @@ println!("u: {}, v: {}, w: {}", u.len(), v.len(), w.len()); // 3, 4, 5
148
147
Use the [ ` iter ` ] ( ../std/vec/trait.ImmutableVector.html#tymethod.iter ) method.
149
148
150
149
~~~
151
- let values: ~[ int] = ~ [1, 2, 3, 4, 5];
150
+ let values: Vec< int> = vec! [1, 2, 3, 4, 5];
152
151
for value in values.iter() { // value: &int
153
152
println!("{}", *value);
154
153
}
0 commit comments