@@ -105,6 +105,7 @@ use option::{None, Option, Some};
105
105
use ptr;
106
106
use ptr:: RawPtr ;
107
107
use to_str:: ToStr ;
108
+ use from_str:: FromStr ;
108
109
use uint;
109
110
use vec;
110
111
use vec:: { OwnedVector , OwnedCopyableVector , ImmutableVector , MutableVector } ;
@@ -204,6 +205,11 @@ impl ToStr for ~str {
204
205
fn to_str ( & self ) -> ~str { self . to_owned ( ) }
205
206
}
206
207
208
+ impl FromStr for ~str {
209
+ #[ inline]
210
+ fn from_str ( s : & str ) -> Option < ~str > { Some ( s. to_owned ( ) ) }
211
+ }
212
+
207
213
impl < ' self > ToStr for & ' self str {
208
214
#[ inline]
209
215
fn to_str ( & self ) -> ~str { self . to_owned ( ) }
@@ -214,6 +220,11 @@ impl ToStr for @str {
214
220
fn to_str ( & self ) -> ~str { self . to_owned ( ) }
215
221
}
216
222
223
+ impl < ' self > FromStr for @str {
224
+ #[ inline]
225
+ fn from_str ( s : & str ) -> Option < @str > { Some ( s. to_managed ( ) ) }
226
+ }
227
+
217
228
/// Convert a byte to a UTF-8 string
218
229
///
219
230
/// # Failure
@@ -2580,13 +2591,14 @@ impl Default for @str {
2580
2591
#[cfg(test)]
2581
2592
mod tests {
2582
2593
use container::Container;
2583
- use option::{None, Some};
2594
+ use option::{None, Some, Option };
2584
2595
use ptr;
2585
2596
use str::*;
2586
2597
use vec;
2587
2598
use vec::{Vector, ImmutableVector, CopyableVector};
2588
2599
use cmp::{TotalOrd, Less, Equal, Greater};
2589
2600
use send_str::{SendStrOwned, SendStrStatic};
2601
+ use from_str::from_str;
2590
2602
2591
2603
#[test]
2592
2604
fn test_eq() {
@@ -3889,6 +3901,14 @@ mod tests {
3889
3901
assert_eq!(" abcde".to_send_str(), SendStrStatic(" abcde"));
3890
3902
assert_eq!(" abcde".to_send_str(), SendStrOwned(~" abcde"));
3891
3903
}
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
+ }
3892
3912
}
3893
3913
3894
3914
#[cfg(test)]
0 commit comments