aboutsummaryrefslogtreecommitdiff
path: root/src/encoder
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2016-06-05 07:46:17 +0200
committerAlex Crichton <alex@alexcrichton.com>2016-06-05 07:46:17 +0200
commitfb8050d2d556dd613971f15e7bd73cfd43acad82 (patch)
treeeaae854e5e6d5b61e9039d30217f821a8a2f30f7 /src/encoder
parent7363dbe7f599a2373e6e2a749f51c76469dabdcf (diff)
parente8097b14f1ea246bf97af380670c502ba1517f30 (diff)
downloadmilf-rs-fb8050d2d556dd613971f15e7bd73cfd43acad82.tar.gz
milf-rs-fb8050d2d556dd613971f15e7bd73cfd43acad82.zip
Merge pull request #101 from leodasvacas/clippy-run
Clippy run and implement Default for State and Enconder
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`");
}
}