forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Doc FAQ Cheatsheet
Huon Wilson edited this page Dec 10, 2013
·
21 revisions
Use ToStr
.
let x: int = 42;
let y: ~str = x.to_str();
Use FromStr
, and its helper function, from_str
.
let x: Option<int> = from_str("42");
let y: int = x.unwrap();
The Container
trait provides the len
method.
let u: ~[u32] = ~[0, 1, 2];
let v: &[u32] = &[0, 1, 2, 3];
let w: [u32, .. 3] = [0, 1, 2, 3, 4];
println!("u: {}, v: {}, w: {}", u.len(), v.len(), w.len()); // 3, 4, 5
For small examples, have full type annotations, as much as is reasonable, to keep it clear what, exactly, everything is doing. Try to link to the API docs, as well.
Similar documents for other programming languages:
All Categories:
- Docs -- For users
- Notes -- For developers
- Libs -- For library authors
- Meeting minutes