Skip to content

Commit eb9635b

Browse files
committed
---
yaml --- r: 81360 b: refs/heads/snap-stage3 c: ccd9a96 h: refs/heads/master v: v3
1 parent 3a3f990 commit eb9635b

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
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 4c6bf4872012c010f84dc7fa2cdfe87522533f89
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 20760739e9bbafc5a7abb0fe4249c5cf6d58ecef
4+
refs/heads/snap-stage3: ccd9a963f75074da506c05fece1e3c965e742c51
55
refs/heads/try: 70152ff55722878cde684ee6462c14c65f2c4729
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/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)