Skip to content

Commit 7869453

Browse files
committed
---
yaml --- r: 149150 b: refs/heads/try2 c: fb12aeb h: refs/heads/master v: v3
1 parent a742879 commit 7869453

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 54760b9f27d2d4ce64f548d27c35cdab73e625ab
8+
refs/heads/try2: fb12aebbd82eb3a7673738f1ed25f428b3d67242
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/doc/complement-cheatsheet.md

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,42 @@ let y: ~str = x.to_str_radix(16);
3636
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).
3737

3838
~~~
39-
use std::num::from_str_radix;
39+
use std::num;
4040
41-
let x: Option<i64> = from_str_radix("deadbeef", 16);
41+
let x: Option<i64> = num::from_str_radix("deadbeef", 16);
4242
let y: i64 = x.unwrap();
4343
~~~
4444

45+
**Vector of Bytes to String**
46+
47+
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).
48+
49+
~~~
50+
use std::str;
51+
52+
let bytes = ~[104u8,105u8];
53+
let x: Option<&str> = str::from_utf8(bytes);
54+
let y: &str = x.unwrap();
55+
~~~
56+
57+
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+
59+
~~~
60+
use std::str;
61+
62+
let x: Option<~str> = str::from_utf8_owned(~[104u8,105u8]);
63+
let y: ~str = x.unwrap();
64+
~~~~
65+
66+
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.
67+
68+
~~~
69+
use std::str;
70+
71+
let x = bytes!(72u8,"ello ",0xF0,0x90,0x80,"World!");
72+
let y = str::from_utf8_lossy(x);
73+
~~~~
74+
4575
# File operations
4676
4777
## How do I read from a file?

0 commit comments

Comments
 (0)