aboutsummaryrefslogtreecommitdiff
path: root/src/encoder
diff options
context:
space:
mode:
Diffstat (limited to 'src/encoder')
-rw-r--r--src/encoder/mod.rs5
-rw-r--r--src/encoder/rustc_serialize.rs10
2 files changed, 10 insertions, 5 deletions
diff --git a/src/encoder/mod.rs b/src/encoder/mod.rs
index fb628fa..304bac6 100644
--- a/src/encoder/mod.rs
+++ b/src/encoder/mod.rs
@@ -35,6 +35,7 @@ use {Value, Table};
/// assert_eq!(e.toml.get(&"foo".to_string()), Some(&Value::Integer(4)))
/// # }
/// ```
+#[derive(Default)]
pub struct Encoder {
/// Output TOML that is emitted. The current version of this encoder forces
/// the top-level representation of a structure to be a table.
@@ -73,6 +74,10 @@ enum State {
NextMapKey,
}
+impl Default for State {
+ fn default() -> State { State::Start }
+}
+
impl Encoder {
/// Constructs a new encoder which will emit to the given output stream.
pub fn new() -> Encoder {
diff --git a/src/encoder/rustc_serialize.rs b/src/encoder/rustc_serialize.rs
index 7f1db87..6dce66a 100644
--- a/src/encoder/rustc_serialize.rs
+++ b/src/encoder/rustc_serialize.rs
@@ -47,10 +47,10 @@ impl rustc_serialize::Encoder for Encoder {
self.emit_value(Value::Float(v))
}
fn emit_char(&mut self, v: char) -> Result<(), Error> {
- self.emit_str(&*format!("{}", v))
+ self.emit_str(&v.to_string())
}
fn emit_str(&mut self, v: &str) -> Result<(), Error> {
- self.emit_value(Value::String(format!("{}", v)))
+ self.emit_value(Value::String(v.to_string()))
}
fn emit_enum<F>(&mut self, _name: &str, f: F)
-> Result<(), Error>
@@ -98,7 +98,7 @@ impl rustc_serialize::Encoder for Encoder {
where F: FnOnce(&mut Encoder) -> Result<(), Error>
{
let old = mem::replace(&mut self.state,
- State::NextKey(format!("{}", f_name)));
+ State::NextKey(f_name.to_string()));
try!(f(self));
if self.state != State::Start {
return Err(NoValue)
@@ -453,7 +453,7 @@ mod tests {
match a {
Ok(..) => panic!("should not have decoded"),
Err(e) => {
- assert_eq!(format!("{}", e),
+ assert_eq!(e.to_string(),
"expected a value of type `integer`, but \
found a value of type `float` for the key `bar`");
}
@@ -471,7 +471,7 @@ mod tests {
match a {
Ok(..) => panic!("should not have decoded"),
Err(e) => {
- assert_eq!(format!("{}", e),
+ assert_eq!(e.to_string(),
"expected a value of type `integer` for the key `bar`");
}
}