Skip to content

Commit e017157

Browse files
committed
---
yaml --- r: 124607 b: refs/heads/auto c: 18717fc h: refs/heads/master i: 124605: e8cbb5d 124603: cfd25c5 124599: 7f4482c 124591: e5aca1b 124575: 23d0bb2 124543: 97a6705 v: v3
1 parent 4249772 commit e017157

File tree

190 files changed

+1486
-3746
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

190 files changed

+1486
-3746
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0
1313
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1414
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1515
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
16-
refs/heads/auto: 50481f55030f02543e1b3b6ae008d77b1cef3e98
16+
refs/heads/auto: 18717fcf6886b803e04bbe21689fd61becab1015
1717
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1818
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
1919
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336

branches/auto/mk/docs.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ DOCS := index intro tutorial guide guide-ffi guide-macros guide-lifetimes \
3030
guide-tasks guide-container guide-pointers guide-testing \
3131
guide-runtime complement-bugreport \
3232
complement-lang-faq complement-design-faq complement-project-faq rust \
33-
rustdoc guide-unsafe guide-strings
33+
rustdoc guide-unsafe
3434

3535
PDF_DOCS := tutorial rust
3636

branches/auto/src/doc/guide-strings.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
% The Strings Guide
22

3+
# Strings
4+
35
Strings are an important concept to master in any programming language. If you
46
come from a managed language background, you may be surprised at the complexity
57
of string handling in a systems programming language. Efficient access and
@@ -12,7 +14,7 @@ Additionally, strings are not null-terminated and can contain null bytes.
1214

1315
Rust has two main types of strings: `&str` and `String`.
1416

15-
# &str
17+
## &str
1618

1719
The first kind is a `&str`. This is pronounced a 'string slice.' String literals
1820
are of the type `&str`:
@@ -36,7 +38,7 @@ Like vector slices, string slices are simply a pointer plus a length. This
3638
means that they're a 'view' into an already-allocated string, such as a
3739
`&'static str` or a `String`.
3840

39-
# String
41+
## String
4042

4143
A `String` is a heap-allocated string. This string is growable, and is also
4244
guaranteed to be UTF-8.
@@ -71,9 +73,9 @@ let x: &[u8] = &[b'a', b'b'];
7173
let stack_str: &str = str::from_utf8(x).unwrap();
7274
```
7375

74-
# Best Practices
76+
## Best Practices
7577

76-
## `String` vs. `&str`
78+
### `String` vs. `&str`
7779

7880
In general, you should prefer `String` when you need ownership, and `&str` when
7981
you just need to borrow a string. This is very similar to using `Vec<T>` vs. `&[T]`,
@@ -96,7 +98,7 @@ need, and it can make your lifetimes more complex. Furthermore, you can pass
9698
either kind of string into `foo` by using `.as_slice()` on any `String` you
9799
need to pass in, so the `&str` version is more flexible.
98100

99-
## Comparisons
101+
### Comparisons
100102

101103
To compare a String to a constant string, prefer `as_slice()`...
102104

@@ -121,7 +123,7 @@ fn compare(string: String) {
121123
Converting a `String` to a `&str` is cheap, but converting the `&str` to a
122124
`String` involves an allocation.
123125

124-
# Other Documentation
126+
## Other Documentation
125127

126128
* [the `&str` API documentation](/std/str/index.html)
127129
* [the `String` API documentation](std/string/index.html)

branches/auto/src/doc/index.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ li {list-style-type: none; }
1313

1414
# Guides
1515

16-
* [Strings](guide-strings.html)
1716
* [Pointers](guide-pointers.html)
1817
* [References and Lifetimes](guide-lifetimes.html)
1918
* [Containers and Iterators](guide-container.html)

branches/auto/src/doc/tutorial.md

Lines changed: 22 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -716,8 +716,8 @@ When an enum has simple integer discriminators, you can apply the `as` cast
716716
operator to convert a variant to its discriminator value as an `int`:
717717

718718
~~~~
719-
# enum Direction { North, East, South, West }
720-
println!( "North => {}", North as int );
719+
# #[deriving(Show)] enum Direction { North }
720+
println!( "{} => {}", North, North as int );
721721
~~~~
722722

723723
It is possible to set the discriminator values to chosen constant values:
@@ -748,23 +748,15 @@ includes an identifier of the actual form that it holds, much like the
748748

749749
This declaration defines a type `Shape` that can refer to such shapes, and two
750750
functions, `Circle` and `Rectangle`, which can be used to construct values of
751-
the type.
752-
753-
To create a new `Circle`, write:
754-
755-
~~~~
756-
# struct Point { x: f64, y: f64 }
757-
# enum Shape { Circle(Point, f64), Rectangle(Point, Point) }
758-
let circle = Circle(Point { x: 0.0, y: 0.0 }, 10.0);
759-
~~~~
751+
the type. To create a new Circle, write `Circle(Point { x: 0.0, y: 0.0 },
752+
10.0)`.
760753

761754
All of these variant constructors may be used as patterns. The only way to
762755
access the contents of an enum instance is the destructuring of a match. For
763756
example:
764757

765758
~~~~
766759
use std::f64;
767-
768760
# struct Point {x: f64, y: f64}
769761
# enum Shape { Circle(Point, f64), Rectangle(Point, Point) }
770762
fn area(sh: Shape) -> f64 {
@@ -773,9 +765,6 @@ fn area(sh: Shape) -> f64 {
773765
Rectangle(Point { x, y }, Point { x: x2, y: y2 }) => (x2 - x) * (y2 - y)
774766
}
775767
}
776-
777-
let rect = Rectangle(Point { x: 0.0, y: 0.0 }, Point { x: 2.0, y: 2.0 });
778-
println!("area: {}", area(rect));
779768
~~~~
780769

781770
Use a lone `_` to ignore an individual field. Ignore all fields of a variant
@@ -797,9 +786,8 @@ fn point_from_direction(dir: Direction) -> Point {
797786
Enum variants may also be structs. For example:
798787

799788
~~~~
800-
#![feature(struct_variant)]
789+
# #![feature(struct_variant)]
801790
use std::f64;
802-
803791
# struct Point { x: f64, y: f64 }
804792
# fn square(x: f64) -> f64 { x * x }
805793
enum Shape {
@@ -814,14 +802,7 @@ fn area(sh: Shape) -> f64 {
814802
}
815803
}
816804
}
817-
818-
fn main() {
819-
let rect = Rectangle {
820-
top_left: Point { x: 0.0, y: 0.0 },
821-
bottom_right: Point { x: 2.0, y: -2.0 }
822-
};
823-
println!("area: {}", area(rect));
824-
}
805+
# fn main() {}
825806
~~~~
826807

827808
> *Note:* This feature of the compiler is currently gated behind the
@@ -1005,10 +986,6 @@ that are `Send`, but non-`Send` types can still *contain* types with custom
1005986
destructors. Example of types which are not `Send` are [`Gc<T>`][gc] and
1006987
[`Rc<T>`][rc], the shared-ownership types.
1007988

1008-
> *Note:* See a [later chapter](#ownership-escape-hatches) for a discussion about
1009-
> [`Gc<T>`][gc] and [`Rc<T>`][rc], and the [chapter about traits](#traits) for
1010-
> a discussion about `Send`.
1011-
1012989
[gc]: http://doc.rust-lang.org/std/gc/struct.Gc.html
1013990
[rc]: http://doc.rust-lang.org/std/rc/struct.Rc.html
1014991

@@ -1668,13 +1645,6 @@ let string = "foobar";
16681645
let view: &str = string.slice(0, 3);
16691646
~~~
16701647

1671-
Square brackets denote indexing into a slice or fixed-size vector:
1672-
1673-
~~~~
1674-
let crayons: [&str, ..3] = ["BananaMania", "Beaver", "Bittersweet"];
1675-
println!("Crayon 2 is '{}'", crayons[2]);
1676-
~~~~
1677-
16781648
Mutable slices also exist, just as there are mutable references. However, there
16791649
are no mutable string slices. Strings are a multi-byte encoding (UTF-8) of
16801650
Unicode code points, so they cannot be freely mutated without the ability to
@@ -1689,6 +1659,20 @@ view[0] = 5;
16891659
let ys: &mut [int] = &mut [1i, 2i, 3i];
16901660
~~~
16911661

1662+
Square brackets denote indexing into a slice or fixed-size vector:
1663+
1664+
~~~~
1665+
# enum Crayon { Almond, AntiqueBrass, Apricot,
1666+
# Aquamarine, Asparagus, AtomicTangerine,
1667+
# BananaMania, Beaver, Bittersweet };
1668+
# fn draw_scene(c: Crayon) { }
1669+
let crayons: [Crayon, ..3] = [BananaMania, Beaver, Bittersweet];
1670+
match crayons[0] {
1671+
Bittersweet => draw_scene(crayons[0]),
1672+
_ => ()
1673+
}
1674+
~~~~
1675+
16921676
A slice or fixed-size vector can be destructured using pattern matching:
16931677

16941678
~~~~
@@ -1754,8 +1738,6 @@ via dynamic checks and can fail at runtime.
17541738
The `Rc` and `Gc` types are not sendable, so they cannot be used to share memory between tasks. Safe
17551739
immutable and mutable shared memory is provided by the `sync::arc` module.
17561740

1757-
> *Note:* See a [later chapter](#traits) for a discussion about `Send` and sendable types.
1758-
17591741
# Closures
17601742

17611743
Named functions, like those we've seen so far, may not refer to local
@@ -2627,7 +2609,7 @@ let nonsense = mycircle.radius() * mycircle.area();
26272609
26282610
## Deriving implementations for traits
26292611

2630-
A small number of traits in can have implementations
2612+
A small number of traits in `std` and `extra` can have implementations
26312613
that can be automatically derived. These instances are specified by
26322614
placing the `deriving` attribute on a data type declaration. For
26332615
example, the following will mean that `Circle` has an implementation
@@ -2636,7 +2618,6 @@ of type `ABC` can be randomly generated and converted to a string:
26362618

26372619
~~~
26382620
extern crate rand;
2639-
use std::rand::{task_rng, Rng};
26402621
26412622
#[deriving(PartialEq)]
26422623
struct Circle { radius: f64 }
@@ -2647,13 +2628,6 @@ enum ABC { A, B, C }
26472628
fn main() {
26482629
// Use the Show trait to print "A, B, C."
26492630
println!("{}, {}, {}", A, B, C);
2650-
2651-
let mut rng = task_rng();
2652-
2653-
// Use the Rand trait to generate a random variants.
2654-
for _ in range(0i, 10) {
2655-
println!("{}", rng.gen::<ABC>());
2656-
}
26572631
}
26582632
~~~
26592633

@@ -3162,8 +3136,8 @@ In Rust terminology, we need a way to refer to other crates.
31623136
For that, Rust offers you the `extern crate` declaration:
31633137

31643138
~~~
3165-
// `num` ships with Rust.
31663139
extern crate num;
3140+
// `num` ships with Rust (much like `extra`; more details further down).
31673141
31683142
fn main() {
31693143
// The rational number '1/2':

branches/auto/src/libcollections/dlist.rs

Lines changed: 3 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,12 @@ impl<T> Rawlink<T> {
8787
}
8888

8989
/// Convert the `Rawlink` into an Option value
90-
fn resolve_immut<'a>(&self) -> Option<&'a T> {
91-
unsafe {
92-
mem::transmute(self.p.to_option())
93-
}
90+
fn resolve_immut(&self) -> Option<&T> {
91+
unsafe { self.p.to_option() }
9492
}
9593

9694
/// Convert the `Rawlink` into an Option value
97-
fn resolve<'a>(&mut self) -> Option<&'a mut T> {
95+
fn resolve(&mut self) -> Option<&mut T> {
9896
if self.p.is_null() {
9997
None
10098
} else {
@@ -280,23 +278,6 @@ impl<T> DList<T> {
280278
/// Move the last element to the front of the list.
281279
///
282280
/// If the list is empty, do nothing.
283-
///
284-
/// # Example
285-
///
286-
/// ```rust
287-
/// use std::collections::{DList, Deque};
288-
///
289-
/// let mut dl = DList::new();
290-
/// dl.push_back(1i);
291-
/// dl.push_back(2);
292-
/// dl.push_back(3);
293-
///
294-
/// dl.rotate_forward();
295-
///
296-
/// for e in dl.iter() {
297-
/// println!("{}", e); // prints 3, then 1, then 2
298-
/// }
299-
/// ```
300281
#[inline]
301282
pub fn rotate_forward(&mut self) {
302283
self.pop_back_node().map(|tail| {
@@ -307,23 +288,6 @@ impl<T> DList<T> {
307288
/// Move the first element to the back of the list.
308289
///
309290
/// If the list is empty, do nothing.
310-
///
311-
/// # Example
312-
///
313-
/// ```rust
314-
/// use std::collections::{DList, Deque};
315-
///
316-
/// let mut dl = DList::new();
317-
/// dl.push_back(1i);
318-
/// dl.push_back(2);
319-
/// dl.push_back(3);
320-
///
321-
/// dl.rotate_backward();
322-
///
323-
/// for e in dl.iter() {
324-
/// println!("{}", e); // prints 2, then 3, then 1
325-
/// }
326-
/// ```
327291
#[inline]
328292
pub fn rotate_backward(&mut self) {
329293
self.pop_front_node().map(|head| {
@@ -334,25 +298,6 @@ impl<T> DList<T> {
334298
/// Add all elements from `other` to the end of the list
335299
///
336300
/// O(1)
337-
///
338-
/// # Example
339-
///
340-
/// ```rust
341-
/// use std::collections::{DList, Deque};
342-
///
343-
/// let mut a = DList::new();
344-
/// let mut b = DList::new();
345-
/// a.push_back(1i);
346-
/// a.push_back(2);
347-
/// b.push_back(3i);
348-
/// b.push_back(4);
349-
///
350-
/// a.append(b);
351-
///
352-
/// for e in a.iter() {
353-
/// println!("{}", e); // prints 1, then 2, then 3, then 4
354-
/// }
355-
/// ```
356301
pub fn append(&mut self, mut other: DList<T>) {
357302
match self.list_tail.resolve() {
358303
None => *self = other,
@@ -375,25 +320,6 @@ impl<T> DList<T> {
375320
/// Add all elements from `other` to the beginning of the list
376321
///
377322
/// O(1)
378-
///
379-
/// # Example
380-
///
381-
/// ```rust
382-
/// use std::collections::{DList, Deque};
383-
///
384-
/// let mut a = DList::new();
385-
/// let mut b = DList::new();
386-
/// a.push_back(1i);
387-
/// a.push_back(2);
388-
/// b.push_back(3i);
389-
/// b.push_back(4);
390-
///
391-
/// a.prepend(b);
392-
///
393-
/// for e in a.iter() {
394-
/// println!("{}", e); // prints 3, then 4, then 1, then 2
395-
/// }
396-
/// ```
397323
#[inline]
398324
pub fn prepend(&mut self, mut other: DList<T>) {
399325
mem::swap(self, &mut other);
@@ -404,25 +330,6 @@ impl<T> DList<T> {
404330
/// or at the end.
405331
///
406332
/// O(N)
407-
///
408-
/// # Example
409-
///
410-
/// ```rust
411-
/// use std::collections::{DList, Deque};
412-
///
413-
/// let mut a: DList<int> = DList::new();
414-
/// a.push_back(2i);
415-
/// a.push_back(4);
416-
/// a.push_back(7);
417-
/// a.push_back(8);
418-
///
419-
/// // insert 11 before the first odd number in the list
420-
/// a.insert_when(11, |&e, _| e % 2 == 1);
421-
///
422-
/// for e in a.iter() {
423-
/// println!("{}", e); // prints 2, then 4, then 11, then 7, then 8
424-
/// }
425-
/// ```
426333
pub fn insert_when(&mut self, elt: T, f: |&T, &T| -> bool) {
427334
{
428335
let mut it = self.mut_iter();

0 commit comments

Comments
 (0)