From 2e24ef377e32ee2fe253046fdc073840279e4b95 Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Sun, 20 Jul 2014 17:12:40 -0700 Subject: Rename to_str to to_string Closes #15796. [breaking-change] --- src/libstd/ascii.rs | 2 +- src/libstd/lib.rs | 2 +- src/libstd/prelude.rs | 2 +- src/libstd/task.rs | 2 +- src/libstd/to_str.rs | 66 ------------------------------------------------- src/libstd/to_string.rs | 66 +++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 70 insertions(+), 70 deletions(-) delete mode 100644 src/libstd/to_str.rs create mode 100644 src/libstd/to_string.rs (limited to 'src/libstd') diff --git a/src/libstd/ascii.rs b/src/libstd/ascii.rs index b9c86e2b235..966e4f8811e 100644 --- a/src/libstd/ascii.rs +++ b/src/libstd/ascii.rs @@ -20,7 +20,7 @@ use option::{Option, Some, None}; use slice::{ImmutableVector, MutableVector, Vector}; use str::{OwnedStr, Str, StrAllocating, StrSlice}; use string::String; -use to_str::{IntoStr}; +use to_string::IntoStr; use vec::Vec; /// Datatype to hold one ascii character. It wraps a `u8`, with the highest bit always zero. diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index ad6942712ac..e14092bc8dc 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -239,7 +239,7 @@ pub mod gc; pub mod from_str; pub mod num; -pub mod to_str; +pub mod to_string; /* Common data structures */ diff --git a/src/libstd/prelude.rs b/src/libstd/prelude.rs index eee494c7bc0..0fa223305a6 100644 --- a/src/libstd/prelude.rs +++ b/src/libstd/prelude.rs @@ -78,7 +78,7 @@ #[doc(no_inline)] pub use io::{Buffer, Writer, Reader, Seek}; #[doc(no_inline)] pub use str::{Str, StrVector, StrSlice, OwnedStr}; #[doc(no_inline)] pub use str::{IntoMaybeOwned, StrAllocating, UnicodeStrSlice}; -#[doc(no_inline)] pub use to_str::{ToString, IntoStr}; +#[doc(no_inline)] pub use to_string::{ToString, IntoStr}; #[doc(no_inline)] pub use tuple::{Tuple1, Tuple2, Tuple3, Tuple4}; #[doc(no_inline)] pub use tuple::{Tuple5, Tuple6, Tuple7, Tuple8}; #[doc(no_inline)] pub use tuple::{Tuple9, Tuple10, Tuple11, Tuple12}; diff --git a/src/libstd/task.rs b/src/libstd/task.rs index 4b8c15a0152..19ad81a0483 100644 --- a/src/libstd/task.rs +++ b/src/libstd/task.rs @@ -106,7 +106,7 @@ use rt::task::Task; use str::{Str, SendStr, IntoMaybeOwned}; use string::String; use sync::Future; -use to_str::ToString; +use to_string::ToString; /// A means of spawning a task pub trait Spawner { diff --git a/src/libstd/to_str.rs b/src/libstd/to_str.rs deleted file mode 100644 index c19fd81b570..00000000000 --- a/src/libstd/to_str.rs +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -/*! - -The `ToString` trait for converting to strings - -*/ - -#![experimental] - -use fmt; -use string::String; - -/// A generic trait for converting a value to a string -pub trait ToString { - /// Converts the value of `self` to an owned string - fn to_string(&self) -> String; -} - -/// Trait for converting a type to a string, consuming it in the process. -pub trait IntoStr { - /// Consume and convert to a string. - fn into_string(self) -> String; -} - -impl ToString for T { - fn to_string(&self) -> String { - format!("{}", *self) - } -} - -#[cfg(test)] -mod tests { - use prelude::*; - use super::*; - - #[test] - fn test_simple_types() { - assert_eq!(1i.to_string(), "1".to_string()); - assert_eq!((-1i).to_string(), "-1".to_string()); - assert_eq!(200u.to_string(), "200".to_string()); - assert_eq!(2u8.to_string(), "2".to_string()); - assert_eq!(true.to_string(), "true".to_string()); - assert_eq!(false.to_string(), "false".to_string()); - assert_eq!(().to_string(), "()".to_string()); - assert_eq!(("hi".to_string()).to_string(), "hi".to_string()); - } - - #[test] - fn test_vectors() { - let x: Vec = vec![]; - assert_eq!(x.to_string(), "[]".to_string()); - assert_eq!((vec![1i]).to_string(), "[1]".to_string()); - assert_eq!((vec![1i, 2, 3]).to_string(), "[1, 2, 3]".to_string()); - assert!((vec![vec![], vec![1i], vec![1i, 1]]).to_string() == - "[[], [1], [1, 1]]".to_string()); - } -} diff --git a/src/libstd/to_string.rs b/src/libstd/to_string.rs new file mode 100644 index 00000000000..c19fd81b570 --- /dev/null +++ b/src/libstd/to_string.rs @@ -0,0 +1,66 @@ +// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +/*! + +The `ToString` trait for converting to strings + +*/ + +#![experimental] + +use fmt; +use string::String; + +/// A generic trait for converting a value to a string +pub trait ToString { + /// Converts the value of `self` to an owned string + fn to_string(&self) -> String; +} + +/// Trait for converting a type to a string, consuming it in the process. +pub trait IntoStr { + /// Consume and convert to a string. + fn into_string(self) -> String; +} + +impl ToString for T { + fn to_string(&self) -> String { + format!("{}", *self) + } +} + +#[cfg(test)] +mod tests { + use prelude::*; + use super::*; + + #[test] + fn test_simple_types() { + assert_eq!(1i.to_string(), "1".to_string()); + assert_eq!((-1i).to_string(), "-1".to_string()); + assert_eq!(200u.to_string(), "200".to_string()); + assert_eq!(2u8.to_string(), "2".to_string()); + assert_eq!(true.to_string(), "true".to_string()); + assert_eq!(false.to_string(), "false".to_string()); + assert_eq!(().to_string(), "()".to_string()); + assert_eq!(("hi".to_string()).to_string(), "hi".to_string()); + } + + #[test] + fn test_vectors() { + let x: Vec = vec![]; + assert_eq!(x.to_string(), "[]".to_string()); + assert_eq!((vec![1i]).to_string(), "[1]".to_string()); + assert_eq!((vec![1i, 2, 3]).to_string(), "[1, 2, 3]".to_string()); + assert!((vec![vec![], vec![1i], vec![1i, 1]]).to_string() == + "[[], [1], [1, 1]]".to_string()); + } +} -- cgit 1.4.1-3-g733a5