Skip to content

Commit 96cf31c

Browse files
committed
---
yaml --- r: 82876 b: refs/heads/auto c: ccd9a96 h: refs/heads/master v: v3
1 parent 6db179c commit 96cf31c

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
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: 20760739e9bbafc5a7abb0fe4249c5cf6d58ecef
16+
refs/heads/auto: ccd9a963f75074da506c05fece1e3c965e742c51
1717
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1818
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
1919
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336

branches/auto/src/libstd/str.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ use option::{None, Option, Some};
105105
use ptr;
106106
use ptr::RawPtr;
107107
use to_str::ToStr;
108+
use from_str::FromStr;
108109
use uint;
109110
use vec;
110111
use vec::{OwnedVector, OwnedCopyableVector, ImmutableVector, MutableVector};
@@ -204,6 +205,11 @@ impl ToStr for ~str {
204205
fn to_str(&self) -> ~str { self.to_owned() }
205206
}
206207

208+
impl FromStr for ~str {
209+
#[inline]
210+
fn from_str(s: &str) -> Option<~str> { Some(s.to_owned()) }
211+
}
212+
207213
impl<'self> ToStr for &'self str {
208214
#[inline]
209215
fn to_str(&self) -> ~str { self.to_owned() }
@@ -214,6 +220,11 @@ impl ToStr for @str {
214220
fn to_str(&self) -> ~str { self.to_owned() }
215221
}
216222

223+
impl<'self> FromStr for @str {
224+
#[inline]
225+
fn from_str(s: &str) -> Option<@str> { Some(s.to_managed()) }
226+
}
227+
217228
/// Convert a byte to a UTF-8 string
218229
///
219230
/// # Failure
@@ -2580,13 +2591,14 @@ impl Default for @str {
25802591
#[cfg(test)]
25812592
mod tests {
25822593
use container::Container;
2583-
use option::{None, Some};
2594+
use option::{None, Some, Option};
25842595
use ptr;
25852596
use str::*;
25862597
use vec;
25872598
use vec::{Vector, ImmutableVector, CopyableVector};
25882599
use cmp::{TotalOrd, Less, Equal, Greater};
25892600
use send_str::{SendStrOwned, SendStrStatic};
2601+
use from_str::from_str;
25902602
25912603
#[test]
25922604
fn test_eq() {
@@ -3889,6 +3901,14 @@ mod tests {
38893901
assert_eq!("abcde".to_send_str(), SendStrStatic("abcde"));
38903902
assert_eq!("abcde".to_send_str(), SendStrOwned(~"abcde"));
38913903
}
3904+
3905+
#[test]
3906+
fn test_from_str() {
3907+
let owned: Option<~str> = from_str(&"string");
3908+
assert_eq!(owned, Some(~"string"));
3909+
let managed: Option<@str> = from_str(&"string");
3910+
assert_eq!(managed, Some(@"string"));
3911+
}
38923912
}
38933913
38943914
#[cfg(test)]

0 commit comments

Comments
 (0)