Skip to content

Commit aa44009

Browse files
committed
---
yaml --- r: 63096 b: refs/heads/snap-stage3 c: 9b0986a h: refs/heads/master v: v3
1 parent ff536f8 commit aa44009

File tree

3 files changed

+12
-34
lines changed

3 files changed

+12
-34
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 2d28d645422c1617be58c8ca7ad9a457264ca850
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 239b81f111d522b1fbb0dbefdde16715ef68a204
4+
refs/heads/snap-stage3: 9b0986acf4397207a29ee6f94433efd5b4b5bc79
55
refs/heads/try: 7b78b52e602bb3ea8174f9b2006bff3315f03ef9
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/doc/tutorial.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -569,8 +569,10 @@ loop {
569569
This code prints out a weird sequence of numbers and stops as soon as
570570
it finds one that can be divided by five.
571571

572-
For more involved iteration, such as enumerating the elements of a
573-
collection, Rust uses [higher-order functions](#closures).
572+
Rust also has a `for` construct. It's different from C's `for` and it works
573+
best when iterating over collections. See the section on [closures](#closures)
574+
to find out how to use `for` and higher-order functions for enumerating
575+
elements of a collection.
574576

575577
# Data structures
576578

@@ -1393,6 +1395,7 @@ assert!(crayons.len() == 3);
13931395
assert!(!crayons.is_empty());
13941396
13951397
// Iterate over a vector, obtaining a pointer to each element
1398+
// (`for` is explained in the next section)
13961399
for crayons.each |crayon| {
13971400
let delicious_crayon_wax = unwrap_crayon(*crayon);
13981401
eat_crayon_wax(delicious_crayon_wax);

branches/snap-stage3/src/libstd/str.rs

Lines changed: 6 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,6 @@ use vec::{OwnedVector, OwnedCopyableVector};
3939

4040
#[cfg(not(test))] use cmp::{Eq, Ord, Equiv, TotalEq};
4141

42-
/*
43-
Section: Conditions
44-
*/
45-
condition! {
46-
not_utf8: (~str) -> ~str;
47-
}
48-
4942
/*
5043
Section: Creating a string
5144
*/
@@ -55,20 +48,11 @@ Section: Creating a string
5548
*
5649
* # Failure
5750
*
58-
* Raises the `not_utf8` condition if invalid UTF-8
51+
* Fails if invalid UTF-8
5952
*/
60-
61-
pub fn from_bytes(vv: &[u8]) -> ~str {
62-
use str::not_utf8::cond;
63-
64-
if !is_utf8(vv) {
65-
let first_bad_byte = vec::find(vv, |b| !is_utf8([*b])).get();
66-
cond.raise(fmt!("from_bytes: input is not UTF-8; first bad byte is %u",
67-
first_bad_byte as uint))
68-
}
69-
else {
70-
return unsafe { raw::from_bytes(vv) }
71-
}
53+
pub fn from_bytes(vv: &const [u8]) -> ~str {
54+
assert!(is_utf8(vv));
55+
return unsafe { raw::from_bytes(vv) };
7256
}
7357

7458
/**
@@ -3579,10 +3563,9 @@ mod tests {
35793563
}
35803564
35813565
#[test]
3566+
#[should_fail]
35823567
#[ignore(cfg(windows))]
35833568
fn test_from_bytes_fail() {
3584-
use str::not_utf8::cond;
3585-
35863569
let bb = ~[0xff_u8, 0xb8_u8, 0xa8_u8,
35873570
0xe0_u8, 0xb9_u8, 0x84_u8,
35883571
0xe0_u8, 0xb8_u8, 0x97_u8,
@@ -3594,15 +3577,7 @@ mod tests {
35943577
0x20_u8, 0x4e_u8, 0x61_u8,
35953578
0x6d_u8];
35963579
3597-
let mut error_happened = false;
3598-
let _x = do cond.trap(|err| {
3599-
assert_eq!(err, ~"from_bytes: input is not UTF-8; first bad byte is 255");
3600-
error_happened = true;
3601-
~""
3602-
}).in {
3603-
from_bytes(bb)
3604-
};
3605-
assert!(error_happened);
3580+
let _x = from_bytes(bb);
36063581
}
36073582
36083583
#[test]

0 commit comments

Comments
 (0)