1
Fork 0

Auto merge of #26028 - steveklabnik:rollup, r=steveklabnik

- Successful merges: #25925, #26001, #26010, #26011, #26017, #26020
- Failed merges:
This commit is contained in:
bors 2015-06-05 11:59:34 +00:00
commit 19a39710c4
7 changed files with 137 additions and 46 deletions

View file

@ -25,7 +25,7 @@ series of small examples.
If you need help with something, or just want to talk about Rust with others, If you need help with something, or just want to talk about Rust with others,
there are a few places you can do that: there are a few places you can do that:
The Rust IRC channels on [irc.mozilla.org](http://irc.mozilla.org/) are the The Rust IRC channels on [irc.mozilla.org](irc://irc.mozilla.org/) are the
fastest way to get help. fastest way to get help.
[`#rust`](http://chat.mibbit.com/?server=irc.mozilla.org&channel=%23rust) is [`#rust`](http://chat.mibbit.com/?server=irc.mozilla.org&channel=%23rust) is
the general discussion channel, and you'll find people willing to help you with the general discussion channel, and you'll find people willing to help you with
@ -40,15 +40,15 @@ There's also
[`#rust-internals`](http://chat.mibbit.com/?server=irc.mozilla.org&channel=%23rust-internals), which is for discussion of the development of Rust itself. [`#rust-internals`](http://chat.mibbit.com/?server=irc.mozilla.org&channel=%23rust-internals), which is for discussion of the development of Rust itself.
You can also get help on [Stack You can also get help on [Stack
Overflow](http://stackoverflow.com/questions/tagged/rust). Searching for your Overflow](https://stackoverflow.com/questions/tagged/rust). Searching for your
problem might reveal someone who has asked it before! problem might reveal someone who has asked it before!
There is an active [subreddit](http://reddit.com/r/rust) with lots of There is an active [subreddit](https://reddit.com/r/rust) with lots of
discussion and news about Rust. discussion and news about Rust.
There is also a [user forum](http://users.rust-lang.org), for all There is also a [user forum](https://users.rust-lang.org), for all
user-oriented discussion, and a [developer user-oriented discussion, and a [developer
forum](http://internals.rust-lang.org/), where the development of Rust forum](https://internals.rust-lang.org/), where the development of Rust
itself is discussed. itself is discussed.
# Specification # Specification
@ -61,7 +61,7 @@ the language in as much detail as possible is in [the reference](reference.html)
Rust is still a young language, so there isn't a ton of tooling yet, but the Rust is still a young language, so there isn't a ton of tooling yet, but the
tools we have are really nice. tools we have are really nice.
[Cargo](http://crates.io) is Rust's package manager, and its website contains [Cargo](https://crates.io) is Rust's package manager, and its website contains
lots of good documentation. lots of good documentation.
[`rustdoc`](book/documentation.html) is used to generate documentation for Rust code. [`rustdoc`](book/documentation.html) is used to generate documentation for Rust code.

View file

@ -41,3 +41,45 @@ so our loop will print `0` through `9`, not `10`.
Rust does not have the “C-style” `for` loop on purpose. Manually controlling Rust does not have the “C-style” `for` loop on purpose. Manually controlling
each element of the loop is complicated and error prone, even for experienced C each element of the loop is complicated and error prone, even for experienced C
developers. developers.
# Enumerate
When you need to keep track of how many times you already looped, you can use the `.enumerate()` function.
## On ranges:
```rust
for (i,j) in (5..10).enumerate() {
println!("i = {} and j = {}", i, j);
}
```
Outputs:
```text
i = 0 and j = 5
i = 1 and j = 6
i = 2 and j = 7
i = 3 and j = 8
i = 4 and j = 9
```
Don't forget to add the parentheses around the range.
## On iterators:
```rust
# let lines = "hello\nworld".lines();
for (linenumber, line) in lines.enumerate() {
println!("{}: {}", linenumber, line);
}
```
Outputs:
```text
0: Content of line one
1: Content of line two
2: Content of line tree
3: Content of line four
```

View file

@ -224,7 +224,7 @@ more" match. Both forms optionally include a separator, which can be any token
except `+` or `*`. except `+` or `*`.
This system is based on This system is based on
"[Macro-by-Example](http://www.cs.indiana.edu/ftp/techreports/TR206.pdf)" "[Macro-by-Example](https://www.cs.indiana.edu/ftp/techreports/TR206.pdf)"
(PDF link). (PDF link).
# Hygiene # Hygiene
@ -319,7 +319,7 @@ syntax context where it was introduced. Its as though the variable `state`
inside `main` is painted a different "color" from the variable `state` inside inside `main` is painted a different "color" from the variable `state` inside
the macro, and therefore they dont conflict. the macro, and therefore they dont conflict.
[hygienic macro system]: http://en.wikipedia.org/wiki/Hygienic_macro [hygienic macro system]: https://en.wikipedia.org/wiki/Hygienic_macro
This also restricts the ability of macros to introduce new bindings at the This also restricts the ability of macros to introduce new bindings at the
invocation site. Code such as the following will not work: invocation site. Code such as the following will not work:
@ -622,7 +622,7 @@ invocation gives you another opportunity to pattern-match the macros
arguments. arguments.
As an extreme example, it is possible, though hardly advisable, to implement As an extreme example, it is possible, though hardly advisable, to implement
the [Bitwise Cyclic Tag](http://esolangs.org/wiki/Bitwise_Cyclic_Tag) automaton the [Bitwise Cyclic Tag](https://esolangs.org/wiki/Bitwise_Cyclic_Tag) automaton
within Rusts macro system. within Rusts macro system.
```rust ```rust

View file

@ -155,7 +155,7 @@ First, any borrow must last for a smaller scope than the owner. Second, you may
have one or the other of these two kinds of borrows, but not both at the same have one or the other of these two kinds of borrows, but not both at the same
time: time:
* 0 to N references (`&T`) to a resource. * one or more references (`&T`) to a resource.
* exactly one mutable reference (`&mut T`) * exactly one mutable reference (`&mut T`)

View file

@ -38,7 +38,7 @@
//! //!
//! * Introducing inherited mutability roots to shared types. //! * Introducing inherited mutability roots to shared types.
//! * Implementation details of logically-immutable methods. //! * Implementation details of logically-immutable methods.
//! * Mutating implementations of `clone`. //! * Mutating implementations of `Clone`.
//! //!
//! ## Introducing inherited mutability roots to shared types //! ## Introducing inherited mutability roots to shared types
//! //!
@ -109,7 +109,7 @@
//! } //! }
//! ``` //! ```
//! //!
//! ## Mutating implementations of `clone` //! ## Mutating implementations of `Clone`
//! //!
//! This is simply a special - but common - case of the previous: hiding mutability for operations //! This is simply a special - but common - case of the previous: hiding mutability for operations
//! that appear to be immutable. The `clone` method is expected to not change the source value, and //! that appear to be immutable. The `clone` method is expected to not change the source value, and

View file

@ -252,8 +252,8 @@ pub fn render(w: &mut fmt::Formatter, s: &str, print_toc: bool) -> fmt::Result {
s.push_str(&format!("<span class='rusttest'>{}</span>", Escape(&test))); s.push_str(&format!("<span class='rusttest'>{}</span>", Escape(&test)));
}); });
s.push_str(&highlight::highlight(&text, s.push_str(&highlight::highlight(&text,
None, Some("rust-example-rendered"),
Some("rust-example-rendered"))); None));
let output = CString::new(s).unwrap(); let output = CString::new(s).unwrap();
hoedown_buffer_puts(ob, output.as_ptr()); hoedown_buffer_puts(ob, output.as_ptr());
}) })

View file

@ -10,37 +10,86 @@
//! Android-specific raw type definitions //! Android-specific raw type definitions
use os::raw::{c_uint, c_uchar, c_ulonglong, c_longlong, c_ulong}; #[doc(inline)]
use os::unix::raw::{uid_t, gid_t}; pub use self::arch::{dev_t, mode_t, blkcnt_t, blksize_t, ino_t, nlink_t, off_t, stat, time_t};
pub type blkcnt_t = u32; #[cfg(target_arch = "arm")]
pub type blksize_t = u32; mod arch {
pub type dev_t = u32; use os::raw::{c_uint, c_uchar, c_ulonglong, c_longlong, c_ulong};
pub type ino_t = u32; use os::unix::raw::{uid_t, gid_t};
pub type mode_t = u16;
pub type nlink_t = u16; pub type dev_t = u32;
pub type off_t = i32; pub type mode_t = u16;
pub type time_t = i32;
pub type blkcnt_t = u32;
pub type blksize_t = u32;
pub type ino_t = u32;
pub type nlink_t = u16;
pub type off_t = i32;
pub type time_t = i32;
#[repr(C)]
pub struct stat {
pub st_dev: c_ulonglong,
pub __pad0: [c_uchar; 4],
pub __st_ino: ino_t,
pub st_mode: c_uint,
pub st_nlink: c_uint,
pub st_uid: uid_t,
pub st_gid: gid_t,
pub st_rdev: c_ulonglong,
pub __pad3: [c_uchar; 4],
pub st_size: c_longlong,
pub st_blksize: blksize_t,
pub st_blocks: c_ulonglong,
pub st_atime: time_t,
pub st_atime_nsec: c_ulong,
pub st_mtime: time_t,
pub st_mtime_nsec: c_ulong,
pub st_ctime: time_t,
pub st_ctime_nsec: c_ulong,
pub st_ino: c_ulonglong,
}
}
#[cfg(target_arch = "aarch64")]
mod arch {
use os::raw::{c_uchar, c_ulong};
use os::unix::raw::{uid_t, gid_t};
pub type dev_t = u64;
pub type mode_t = u32;
pub type blkcnt_t = u64;
pub type blksize_t = u32;
pub type ino_t = u64;
pub type nlink_t = u32;
pub type off_t = i64;
pub type time_t = i64;
#[repr(C)]
pub struct stat {
pub st_dev: dev_t,
pub __pad0: [c_uchar; 4],
pub __st_ino: ino_t,
pub st_mode: mode_t,
pub st_nlink: nlink_t,
pub st_uid: uid_t,
pub st_gid: gid_t,
pub st_rdev: dev_t,
pub __pad3: [c_uchar; 4],
pub st_size: off_t,
pub st_blksize: blksize_t,
pub st_blocks: blkcnt_t,
pub st_atime: time_t,
pub st_atime_nsec: c_ulong,
pub st_mtime: time_t,
pub st_mtime_nsec: c_ulong,
pub st_ctime: time_t,
pub st_ctime_nsec: c_ulong,
pub st_ino: ino_t,
}
#[repr(C)]
pub struct stat {
pub st_dev: c_ulonglong,
pub __pad0: [c_uchar; 4],
pub __st_ino: ino_t,
pub st_mode: c_uint,
pub st_nlink: c_uint,
pub st_uid: uid_t,
pub st_gid: gid_t,
pub st_rdev: c_ulonglong,
pub __pad3: [c_uchar; 4],
pub st_size: c_longlong,
pub st_blksize: blksize_t,
pub st_blocks: c_ulonglong,
pub st_atime: time_t,
pub st_atime_nsec: c_ulong,
pub st_mtime: time_t,
pub st_mtime_nsec: c_ulong,
pub st_ctime: time_t,
pub st_ctime_nsec: c_ulong,
pub st_ino: c_ulonglong,
} }