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
+13-12Lines changed: 13 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,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;
11
-
let y: ~str = x.to_str();
11
+
let y: StrBuf = x.to_str().to_strbuf();
12
12
~~~
13
13
14
14
**String to int**
@@ -22,14 +22,14 @@ let y: int = x.unwrap();
22
22
23
23
**Int to string, in non-base-10**
24
24
25
-
Use the `format!` syntax extension.
25
+
Use the `format_strbuf!` syntax extension.
26
26
27
27
~~~
28
28
let x: int = 42;
29
-
let y: ~str = format!("{:t}", x); // binary
30
-
let y: ~str = format!("{:o}", x); // octal
31
-
let y: ~str = format!("{:x}", x); // lowercase hexadecimal
32
-
let y: ~str = format!("{:X}", x); // uppercase hexadecimal
29
+
let y: StrBuf = format_strbuf!("{:t}", x); // binary
30
+
let y: StrBuf = format_strbuf!("{:o}", x); // octal
31
+
let y: StrBuf = format_strbuf!("{:x}", x); // lowercase hexadecimal
32
+
let y: StrBuf = format_strbuf!("{:X}", x); // uppercase hexadecimal
33
33
~~~
34
34
35
35
**String to int, in non-base-10**
@@ -55,13 +55,14 @@ let x: Option<&str> = str::from_utf8(bytes);
55
55
let y: &str = x.unwrap();
56
56
~~~
57
57
58
-
To return an Owned String (~str) use the str helper function [`from_utf8_owned`](http://static.rust-lang.org/doc/master/std/str/fn.from_utf8_owned.html).
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).
59
59
60
60
~~~
61
61
use std::str;
62
62
63
-
let x: Result<~str,~[u8]> = str::from_utf8_owned(~[104u8,105u8]);
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.
@@ -181,7 +182,7 @@ enum Closed {}
181
182
Phantom types are useful for enforcing state at compile time. For example:
0 commit comments