ToStr::to_str -> ToString::to_string

This commit is contained in:
Michael Gehring 2014-07-09 15:35:54 +02:00
parent 624d539818
commit 46ab9eb436
3 changed files with 26 additions and 26 deletions

View file

@ -187,10 +187,10 @@ impl serialize::Encoder<Error> for Encoder {
self.emit_value(Float(v)) self.emit_value(Float(v))
} }
fn emit_char(&mut self, v: char) -> Result<(), Error> { fn emit_char(&mut self, v: char) -> Result<(), Error> {
self.emit_str(v.to_str().as_slice()) self.emit_str(v.to_string().as_slice())
} }
fn emit_str(&mut self, v: &str) -> Result<(), Error> { fn emit_str(&mut self, v: &str) -> Result<(), Error> {
self.emit_value(String(v.to_str())) self.emit_value(String(v.to_string()))
} }
fn emit_enum(&mut self, _name: &str, fn emit_enum(&mut self, _name: &str,
f: |&mut Encoder| -> Result<(), Error>) -> Result<(), Error> { f: |&mut Encoder| -> Result<(), Error>) -> Result<(), Error> {
@ -245,7 +245,7 @@ impl serialize::Encoder<Error> for Encoder {
f: |&mut Encoder| -> Result<(), Error>) f: |&mut Encoder| -> Result<(), Error>)
-> Result<(), Error> -> Result<(), Error>
{ {
let old = mem::replace(&mut self.state, NextKey(f_name.to_str())); let old = mem::replace(&mut self.state, NextKey(f_name.to_string()));
try!(f(self)); try!(f(self));
if self.state != Start { if self.state != Start {
println!("{}", self.state); println!("{}", self.state);
@ -762,7 +762,7 @@ mod tests {
macro_rules! map( ($($k:ident: $v:expr),*) => ({ macro_rules! map( ($($k:ident: $v:expr),*) => ({
let mut _m = HashMap::new(); let mut _m = HashMap::new();
$(_m.insert(stringify!($k).to_str(), $v);)* $(_m.insert(stringify!($k).to_string(), $v);)*
_m _m
}) ) }) )
@ -907,7 +907,7 @@ mod tests {
foo: Integer(10), foo: Integer(10),
bar: Integer(4) bar: Integer(4)
}), }),
set: Array(vec![String("a".to_str())]) set: Array(vec![String("a".to_string())])
} }
); );
assert_eq!(v, decode!(Table(encode!(v)))); assert_eq!(v, decode!(Table(encode!(v))));
@ -962,7 +962,7 @@ mod tests {
match a { match a {
Ok(..) => fail!("should not have decoded"), Ok(..) => fail!("should not have decoded"),
Err(e) => { Err(e) => {
assert_eq!(e.to_str().as_slice(), assert_eq!(e.to_string().as_slice(),
"expected a value of type `integer`, but \ "expected a value of type `integer`, but \
found a value of type `float` for the key `bar`"); found a value of type `float` for the key `bar`");
} }
@ -980,7 +980,7 @@ mod tests {
match a { match a {
Ok(..) => fail!("should not have decoded"), Ok(..) => fail!("should not have decoded"),
Err(e) => { Err(e) => {
assert_eq!(e.to_str().as_slice(), assert_eq!(e.to_string().as_slice(),
"expected a value of type `integer` for the key `bar`"); "expected a value of type `integer` for the key `bar`");
} }
} }

View file

@ -105,42 +105,42 @@ mod tests {
macro_rules! map( ($($k:expr: $v:expr),*) => ({ macro_rules! map( ($($k:expr: $v:expr),*) => ({
let mut _m = HashMap::new(); let mut _m = HashMap::new();
$(_m.insert($k.to_str(), $v);)* $(_m.insert($k.to_string(), $v);)*
_m _m
}) ) }) )
#[test] #[test]
fn simple_show() { fn simple_show() {
assert_eq!(String("foo".to_str()).to_str().as_slice(), assert_eq!(String("foo".to_string()).to_string().as_slice(),
"\"foo\"") "\"foo\"")
assert_eq!(Integer(10).to_str().as_slice(), assert_eq!(Integer(10).to_string().as_slice(),
"10") "10")
assert_eq!(Float(10.0).to_str().as_slice(), assert_eq!(Float(10.0).to_string().as_slice(),
"10.0") "10.0")
assert_eq!(Float(2.4).to_str().as_slice(), assert_eq!(Float(2.4).to_string().as_slice(),
"2.4") "2.4")
assert_eq!(Boolean(true).to_str().as_slice(), assert_eq!(Boolean(true).to_string().as_slice(),
"true") "true")
assert_eq!(Datetime("test".to_str()).to_str().as_slice(), assert_eq!(Datetime("test".to_string()).to_string().as_slice(),
"test") "test")
assert_eq!(Array(vec![]).to_str().as_slice(), assert_eq!(Array(vec![]).to_string().as_slice(),
"[]") "[]")
assert_eq!(Array(vec![Integer(1), Integer(2)]).to_str().as_slice(), assert_eq!(Array(vec![Integer(1), Integer(2)]).to_string().as_slice(),
"[1, 2]") "[1, 2]")
} }
#[test] #[test]
fn table() { fn table() {
assert_eq!(Table(map! { }).to_str().as_slice(), assert_eq!(Table(map! { }).to_string().as_slice(),
"") "")
assert_eq!(Table(map! { "test": Integer(2) }).to_str().as_slice(), assert_eq!(Table(map! { "test": Integer(2) }).to_string().as_slice(),
"test = 2\n") "test = 2\n")
assert_eq!(Table(map! { assert_eq!(Table(map! {
"test": Integer(2), "test": Integer(2),
"test2": Table(map! { "test2": Table(map! {
"test": String("wut".to_str()) "test": String("wut".to_string())
}) })
}).to_str().as_slice(), }).to_string().as_slice(),
"test = 2\n\ "test = 2\n\
\n\ \n\
[test2]\n\ [test2]\n\
@ -148,9 +148,9 @@ mod tests {
assert_eq!(Table(map! { assert_eq!(Table(map! {
"test": Integer(2), "test": Integer(2),
"test2": Table(map! { "test2": Table(map! {
"test": String("wut".to_str()) "test": String("wut".to_string())
}) })
}).to_str().as_slice(), }).to_string().as_slice(),
"test = 2\n\ "test = 2\n\
\n\ \n\
[test2]\n\ [test2]\n\
@ -158,9 +158,9 @@ mod tests {
assert_eq!(Table(map! { assert_eq!(Table(map! {
"test": Integer(2), "test": Integer(2),
"test2": Array(vec![Table(map! { "test2": Array(vec![Table(map! {
"test": String("wut".to_str()) "test": String("wut".to_string())
})]) })])
}).to_str().as_slice(), }).to_string().as_slice(),
"test = 2\n\ "test = 2\n\
\n\ \n\
[[test2]]\n\ [[test2]]\n\

View file

@ -15,7 +15,7 @@ fn to_json(toml: Value) -> json::Json {
} }
match toml { match toml {
String(s) => doit("string", json::String(s)), String(s) => doit("string", json::String(s)),
Integer(i) => doit("integer", json::String(i.to_str())), Integer(i) => doit("integer", json::String(i.to_string())),
Float(f) => doit("float", json::String({ Float(f) => doit("float", json::String({
let (bytes, _) = let (bytes, _) =
strconv::float_to_str_bytes_common(f, 10, true, strconv::float_to_str_bytes_common(f, 10, true,
@ -26,7 +26,7 @@ fn to_json(toml: Value) -> json::Json {
let s = String::from_utf8(bytes).unwrap(); let s = String::from_utf8(bytes).unwrap();
if s.as_slice().contains(".") {s} else {format!("{}.0", s)} if s.as_slice().contains(".") {s} else {format!("{}.0", s)}
})), })),
Boolean(b) => doit("bool", json::String(b.to_str())), Boolean(b) => doit("bool", json::String(b.to_string())),
Datetime(s) => doit("datetime", json::String(s)), Datetime(s) => doit("datetime", json::String(s)),
Array(arr) => { Array(arr) => {
let is_table = match arr.as_slice().head() { let is_table = match arr.as_slice().head() {