about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/libserialize/base64.rs7
-rw-r--r--src/libserialize/hex.rs5
-rw-r--r--src/libstd/num/strconv.rs1
-rw-r--r--src/libstd/strbuf.rs14
4 files changed, 15 insertions, 12 deletions
diff --git a/src/libserialize/base64.rs b/src/libserialize/base64.rs
index 4709365ebff..5702557526f 100644
--- a/src/libserialize/base64.rs
+++ b/src/libserialize/base64.rs
@@ -181,9 +181,8 @@ impl<'a> FromBase64 for &'a str {
      * Convert any base64 encoded string (literal, `@`, `&`, or `~`)
      * to the byte values it encodes.
      *
-     * You can use the `from_utf8_owned` function in `std::str`
-     * to turn a `[u8]` into a string with characters corresponding to those
-     * values.
+     * You can use the `StrBuf::from_utf8` function in `std::strbuf` to turn a
+     * `Vec<u8>` into a string with characters corresponding to those values.
      *
      * # Example
      *
@@ -199,7 +198,7 @@ impl<'a> FromBase64 for &'a str {
      *     let res = hello_str.from_base64();
      *     if res.is_ok() {
      *       let opt_bytes = StrBuf::from_utf8(res.unwrap());
-     *       if opt_bytes.is_some() {
+     *       if opt_bytes.is_ok() {
      *         println!("decoded from base64: {}", opt_bytes.unwrap());
      *       }
      *     }
diff --git a/src/libserialize/hex.rs b/src/libserialize/hex.rs
index c463d97dba4..2b9ba763b2e 100644
--- a/src/libserialize/hex.rs
+++ b/src/libserialize/hex.rs
@@ -80,9 +80,8 @@ impl<'a> FromHex for &'a str {
      * Convert any hexadecimal encoded string (literal, `@`, `&`, or `~`)
      * to the byte values it encodes.
      *
-     * You can use the `from_utf8_owned` function in `std::str`
-     * to turn a `[u8]` into a string with characters corresponding to those
-     * values.
+     * You can use the `StrBuf::from_utf8` function in `std::strbuf` to turn a
+     * `Vec<u8>` into a string with characters corresponding to those values.
      *
      * # Example
      *
diff --git a/src/libstd/num/strconv.rs b/src/libstd/num/strconv.rs
index 4769b17fb2b..63d6219ab8a 100644
--- a/src/libstd/num/strconv.rs
+++ b/src/libstd/num/strconv.rs
@@ -19,6 +19,7 @@ use num::{Float, FPNaN, FPInfinite, ToPrimitive};
 use num;
 use ops::{Add, Sub, Mul, Div, Rem, Neg};
 use option::{None, Option, Some};
+use result::ResultUnwrap;
 use slice::{CloneableVector, ImmutableVector, MutableVector};
 use std::cmp::{Ord, Eq};
 use str::{StrAllocating, StrSlice};
diff --git a/src/libstd/strbuf.rs b/src/libstd/strbuf.rs
index 575de89fae2..de480ef1b7f 100644
--- a/src/libstd/strbuf.rs
+++ b/src/libstd/strbuf.rs
@@ -20,6 +20,7 @@ use mem;
 use option::{None, Option, Some};
 use ptr::RawPtr;
 use ptr;
+use result::{Result, Ok, Err};
 use slice::{OwnedVector, Vector, CloneableVector};
 use str::{CharRange, OwnedStr, Str, StrSlice, StrAllocating};
 use str;
@@ -72,14 +73,17 @@ impl StrBuf {
         }
     }
 
-    /// Tries to create a new string buffer from the given byte
-    /// vector, validating that the vector is UTF-8 encoded.
+    /// Returns the vector as a string buffer, if possible, taking care not to
+    /// copy it.
+    ///
+    /// Returns `Err` with the original vector if the vector contains invalid
+    /// UTF-8.
     #[inline]
-    pub fn from_utf8(vec: Vec<u8>) -> Option<StrBuf> {
+    pub fn from_utf8(vec: Vec<u8>) -> Result<StrBuf, Vec<u8>> {
         if str::is_utf8(vec.as_slice()) {
-            Some(StrBuf { vec: vec })
+            Ok(StrBuf { vec: vec })
         } else {
-            None
+            Err(vec)
         }
     }