From be43625082bf14f7ca49c9edc4b8a899fd73eddf Mon Sep 17 00:00:00 2001 From: Corey Richardson Date: Thu, 5 Sep 2013 00:48:48 -0400 Subject: Add a from_str function that calls out to the associated method on the trait --- src/libstd/from_str.rs | 4 ++++ src/libstd/prelude.rs | 1 + 2 files changed, 5 insertions(+) (limited to 'src/libstd') diff --git a/src/libstd/from_str.rs b/src/libstd/from_str.rs index d2f1a895e1e..a2417ae70cc 100644 --- a/src/libstd/from_str.rs +++ b/src/libstd/from_str.rs @@ -19,3 +19,7 @@ pub trait FromStr { /// string is ill-formatted, the None is returned. fn from_str(s: &str) -> Option; } + +pub fn from_str(s: &str) -> Option { + FromStr::from_str(s) +} diff --git a/src/libstd/prelude.rs b/src/libstd/prelude.rs index 8f202ee8531..9cdf7af091f 100644 --- a/src/libstd/prelude.rs +++ b/src/libstd/prelude.rs @@ -41,6 +41,7 @@ pub use result::{Result, Ok, Err}; // Reexported functions pub use io::{print, println}; pub use iterator::range; +pub use from_str::from_str; // Reexported types and traits pub use c_str::ToCStr; -- cgit 1.4.1-3-g733a5 From c1c5c8b725165546a5a2b158ad46888aee5df241 Mon Sep 17 00:00:00 2001 From: Corey Richardson Date: Thu, 5 Sep 2013 00:58:12 -0400 Subject: Add from_str docs --- src/libstd/from_str.rs | 1 + 1 file changed, 1 insertion(+) (limited to 'src/libstd') diff --git a/src/libstd/from_str.rs b/src/libstd/from_str.rs index a2417ae70cc..e5bf9f6bb2a 100644 --- a/src/libstd/from_str.rs +++ b/src/libstd/from_str.rs @@ -20,6 +20,7 @@ pub trait FromStr { fn from_str(s: &str) -> Option; } +/// A utility function that just calls FromStr::from_str pub fn from_str(s: &str) -> Option { FromStr::from_str(s) } -- cgit 1.4.1-3-g733a5 From e0e5523552c5b7ae6c7175c5e7aeefbac5fd0ba1 Mon Sep 17 00:00:00 2001 From: Corey Richardson Date: Sun, 8 Sep 2013 15:00:00 -0400 Subject: Fix import order which caused the wrong from_str to be in scope --- src/libstd/num/float.rs | 2 +- src/libstd/num/int_macros.rs | 2 +- src/libstd/num/uint_macros.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/num/float.rs b/src/libstd/num/float.rs index 4dd6fd25333..df26fadae16 100644 --- a/src/libstd/num/float.rs +++ b/src/libstd/num/float.rs @@ -946,8 +946,8 @@ impl Float for float { #[cfg(test)] mod tests { - use super::*; use prelude::*; + use super::*; use num::*; use num; diff --git a/src/libstd/num/int_macros.rs b/src/libstd/num/int_macros.rs index 0131feda830..0ae499d47d9 100644 --- a/src/libstd/num/int_macros.rs +++ b/src/libstd/num/int_macros.rs @@ -547,8 +547,8 @@ impl ToStrRadix for $T { #[cfg(test)] mod tests { - use super::*; use prelude::*; + use super::*; use int; use i16; diff --git a/src/libstd/num/uint_macros.rs b/src/libstd/num/uint_macros.rs index 1426142d465..d2c0f0bf90b 100644 --- a/src/libstd/num/uint_macros.rs +++ b/src/libstd/num/uint_macros.rs @@ -430,8 +430,8 @@ impl BitCount for $T { #[cfg(test)] mod tests { - use super::*; use prelude::*; + use super::*; use num; use sys; -- cgit 1.4.1-3-g733a5