Skip to content

Documentation fixups and tweaks #14348

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 23, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

If you're just reporting a bug, please see:

http://static.rust-lang.org/doc/master/complement-bugreport.html
http://doc.rust-lang.org/complement-bugreport.html

## Pull request procedure

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ documentation.
> [getting started][wiki-start] notes on the wiki.

[installer]: http://www.rust-lang.org/install.html
[tutorial]: http://static.rust-lang.org/doc/tutorial.html
[tutorial]: http://doc.rust-lang.org/tutorial.html
[wiki-start]: https://github.com/mozilla/rust/wiki/Note-getting-started-developing-Rust
[win-wiki]: https://github.com/mozilla/rust/wiki/Using-Rust-on-Windows

Expand Down Expand Up @@ -60,7 +60,7 @@ documentation.

[repo]: https://github.com/mozilla/rust
[tarball]: http://static.rust-lang.org/dist/rust-nightly.tar.gz
[tutorial]: http://static.rust-lang.org/doc/master/tutorial.html
[tutorial]: http://doc.rust-lang.org/tutorial.html

## Notes

Expand Down
2 changes: 1 addition & 1 deletion mk/docs.mk
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ doc/footer.tex: $(D)/footer.inc | doc/
# HTML (rustdoc)
DOC_TARGETS += doc/not_found.html
doc/not_found.html: $(D)/not_found.md $(HTML_DEPS) | doc/
$(RUSTDOC) $(RUSTDOC_HTML_OPTS_NO_CSS) --markdown-css http://static.rust-lang.org/doc/master/rust.css $<
$(RUSTDOC) $(RUSTDOC_HTML_OPTS_NO_CSS) --markdown-css http://doc.rust-lang.org/rust.css $<

define DEF_DOC

Expand Down
40 changes: 28 additions & 12 deletions src/doc/complement-cheatsheet.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

**Int to string**

Use [`ToStr`](http://static.rust-lang.org/doc/master/std/to_str/trait.ToStr.html).
Use [`ToStr`](../std/to_str/trait.ToStr.html).

~~~
let x: int = 42;
Expand All @@ -13,7 +13,8 @@ let y: StrBuf = x.to_str().to_strbuf();

**String to int**

Use [`FromStr`](http://static.rust-lang.org/doc/master/std/from_str/trait.FromStr.html), and its helper function, [`from_str`](http://static.rust-lang.org/doc/master/std/from_str/fn.from_str.html).
Use [`FromStr`](../std/from_str/trait.FromStr.html), and its helper function,
[`from_str`](../std/from_str/fn.from_str.html).

~~~
let x: Option<int> = from_str("42");
Expand All @@ -34,7 +35,8 @@ let y: StrBuf = format_strbuf!("{:X}", x); // uppercase hexadecimal

**String to int, in non-base-10**

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).
Use [`FromStrRadix`](../std/num/trait.FromStrRadix.html), and its helper
function, [`from_str_radix`](../std/num/fn.from_str_radix.html).

~~~
use std::num;
Expand All @@ -45,7 +47,8 @@ let y: i64 = x.unwrap();

**Vector of Bytes to String**

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).
To return a Borrowed String Slice (&str) use the str helper function
[`from_utf8`](../std/str/fn.from_utf8.html).

~~~
use std::str;
Expand All @@ -55,7 +58,8 @@ let x: Option<&str> = str::from_utf8(bytes);
let y: &str = x.unwrap();
~~~

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).
To return an Owned String (StrBuf) use the str helper function
[`from_utf8_owned`](../std/str/fn.from_utf8_owned.html).

~~~
use std::str;
Expand All @@ -65,7 +69,10 @@ let x: Result<StrBuf,~[u8]> =
let y: StrBuf = x.unwrap();
~~~

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.
To return a [`MaybeOwned`](../std/str/enum.MaybeOwned.html) use the str helper
function [`from_utf8_lossy`](../std/str/fn.from_utf8_owned.html).
This function also replaces non-valid utf-8 sequences with U+FFFD replacement
character.

~~~
use std::str;
Expand All @@ -78,7 +85,13 @@ let y = str::from_utf8_lossy(x);

## How do I read from a file?

Use [`File::open`](http://static.rust-lang.org/doc/master/std/io/fs/struct.File.html#method.open) to create a [`File`](http://static.rust-lang.org/doc/master/std/io/fs/struct.File.html) struct, which implements the [`Reader`](http://static.rust-lang.org/doc/master/std/io/trait.Reader.html) trait.
Use
[`File::open`](../std/io/fs/struct.File.html#method.open)
to create a
[`File`](../std/io/fs/struct.File.html)
struct, which implements the
[`Reader`](../std/io/trait.Reader.html)
trait.

~~~ {.ignore}
use std::path::Path;
Expand All @@ -91,7 +104,7 @@ let reader : File = File::open(&path).unwrap_or_else(on_error);

## How do I iterate over the lines in a file?

Use the [`lines`](http://static.rust-lang.org/doc/master/std/io/trait.Buffer.html#method.lines) method on a [`BufferedReader`](http://static.rust-lang.org/doc/master/std/io/buffered/struct.BufferedReader.html).
Use the [`lines`](../std/io/trait.Buffer.html#method.lines) method on a [`BufferedReader`](../std/io/buffered/struct.BufferedReader.html).

~~~
use std::io::BufferedReader;
Expand All @@ -109,7 +122,7 @@ for line in reader.lines() {

## How do I search for a substring?

Use the [`find_str`](http://static.rust-lang.org/doc/master/std/str/trait.StrSlice.html#tymethod.find_str) method.
Use the [`find_str`](../std/str/trait.StrSlice.html#tymethod.find_str) method.

~~~
let str = "Hello, this is some random string";
Expand All @@ -120,7 +133,7 @@ let index: Option<uint> = str.find_str("rand");

## How do I get the length of a vector?

The [`Container`](http://static.rust-lang.org/doc/master/std/container/trait.Container.html) trait provides the `len` method.
The [`Container`](../std/container/trait.Container.html) trait provides the `len` method.

~~~
let u: ~[u32] = ~[0, 1, 2];
Expand All @@ -132,7 +145,7 @@ println!("u: {}, v: {}, w: {}", u.len(), v.len(), w.len()); // 3, 4, 5

## How do I iterate over a vector?

Use the [`iter`](http://static.rust-lang.org/doc/master/std/vec/trait.ImmutableVector.html#tymethod.iter) method.
Use the [`iter`](../std/vec/trait.ImmutableVector.html#tymethod.iter) method.

~~~
let values: ~[int] = ~[1, 2, 3, 4, 5];
Expand All @@ -141,7 +154,10 @@ for value in values.iter() { // value: &int
}
~~~

(See also [`mut_iter`](http://static.rust-lang.org/doc/master/std/vec/trait.MutableVector.html#tymethod.mut_iter) which yields `&mut int` and [`move_iter`](http://static.rust-lang.org/doc/master/std/vec/trait.OwnedVector.html#tymethod.move_iter) which yields `int` while consuming the `values` vector.)
(See also [`mut_iter`](../std/vec/trait.MutableVector.html#tymethod.mut_iter)
which yields `&mut int` and
[`move_iter`](../std/vec/trait.OwnedVector.html#tymethod.move_iter) which yields
`int` while consuming the `values` vector.)

# Type system

Expand Down
Loading