Skip to content

Commit e123210

Browse files
committed
---
yaml --- r: 151735 b: refs/heads/try2 c: ba7844a h: refs/heads/master i: 151733: e706dfb 151731: 0f93f34 151727: 3c8b18d v: v3
1 parent c35c92a commit e123210

File tree

5 files changed

+16
-13
lines changed

5 files changed

+16
-13
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: d0f3cb05df41b14b58553fab6a533e0e4c947b06
8+
refs/heads/try2: ba7844a7fff0061e5b4528c2ecd5adf765145b70
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/libserialize/base64.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,8 @@ impl<'a> FromBase64 for &'a str {
181181
* Convert any base64 encoded string (literal, `@`, `&`, or `~`)
182182
* to the byte values it encodes.
183183
*
184-
* You can use the `from_utf8_owned` function in `std::str`
185-
* to turn a `[u8]` into a string with characters corresponding to those
186-
* values.
184+
* You can use the `StrBuf::from_utf8` function in `std::strbuf` to turn a
185+
* `Vec<u8>` into a string with characters corresponding to those values.
187186
*
188187
* # Example
189188
*
@@ -199,7 +198,7 @@ impl<'a> FromBase64 for &'a str {
199198
* let res = hello_str.from_base64();
200199
* if res.is_ok() {
201200
* let opt_bytes = StrBuf::from_utf8(res.unwrap());
202-
* if opt_bytes.is_some() {
201+
* if opt_bytes.is_ok() {
203202
* println!("decoded from base64: {}", opt_bytes.unwrap());
204203
* }
205204
* }

branches/try2/src/libserialize/hex.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,8 @@ impl<'a> FromHex for &'a str {
8080
* Convert any hexadecimal encoded string (literal, `@`, `&`, or `~`)
8181
* to the byte values it encodes.
8282
*
83-
* You can use the `from_utf8_owned` function in `std::str`
84-
* to turn a `[u8]` into a string with characters corresponding to those
85-
* values.
83+
* You can use the `StrBuf::from_utf8` function in `std::strbuf` to turn a
84+
* `Vec<u8>` into a string with characters corresponding to those values.
8685
*
8786
* # Example
8887
*

branches/try2/src/libstd/num/strconv.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use num::{Float, FPNaN, FPInfinite, ToPrimitive};
1919
use num;
2020
use ops::{Add, Sub, Mul, Div, Rem, Neg};
2121
use option::{None, Option, Some};
22+
use result::ResultUnwrap;
2223
use slice::{CloneableVector, ImmutableVector, MutableVector};
2324
use std::cmp::{Ord, Eq};
2425
use str::{StrAllocating, StrSlice};

branches/try2/src/libstd/strbuf.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use mem;
2020
use option::{None, Option, Some};
2121
use ptr::RawPtr;
2222
use ptr;
23+
use result::{Result, Ok, Err};
2324
use slice::{OwnedVector, Vector, CloneableVector};
2425
use str::{CharRange, OwnedStr, Str, StrSlice, StrAllocating};
2526
use str;
@@ -72,14 +73,17 @@ impl StrBuf {
7273
}
7374
}
7475

75-
/// Tries to create a new string buffer from the given byte
76-
/// vector, validating that the vector is UTF-8 encoded.
76+
/// Returns the vector as a string buffer, if possible, taking care not to
77+
/// copy it.
78+
///
79+
/// Returns `Err` with the original vector if the vector contains invalid
80+
/// UTF-8.
7781
#[inline]
78-
pub fn from_utf8(vec: Vec<u8>) -> Option<StrBuf> {
82+
pub fn from_utf8(vec: Vec<u8>) -> Result<StrBuf, Vec<u8>> {
7983
if str::is_utf8(vec.as_slice()) {
80-
Some(StrBuf { vec: vec })
84+
Ok(StrBuf { vec: vec })
8185
} else {
82-
None
86+
Err(vec)
8387
}
8488
}
8589

0 commit comments

Comments
 (0)