Repository: slog-rs/slog (language: rust)

Issue:
Missing length parameter for SerdeSerializer::start(...)
For the JSON formatter (`slog_json`) this isn't necessary. However, some Serde-based formatters do need it.

My particular use-case is MessagePack, which [requires the length for a map](https://github.com/msgpack/msgpack/blob/master/spec.md#formats-map). This is carried forward to the [serde implementation of messagepack](https://docs.rs/rmp-serde/0.10.0/src/rmp_serde/.cargo/registry/src/github.com-1ecc6299db9ec823/rmp-serde-0.10.0/src/encode.rs.html#352-362), which requires a non-`None` length parameter.

However, since the `start` function on `SerdeSerializer` assumes that the length is `None`, it is impossible to use it with certain Serde formatters.

This appears to be a pretty easy change to make, though it'd be breaking for any package using `::start` directly instead of something like `slog-json`.


Discussion / hints:
I'm glad to hear you are investigating `msgpack` support. `slog-serde` is not `1.0.0` yet, so breaking it is not a problem. Feel free to hack on it and submit a PR. Also if you'd like make `slog-msgpack` crate I can create a repo in `slog` community and make you and admin.


Fix patch:
diff --git a/crates/json/lib.rs b/crates/json/lib.rs
index b0f2f1126..af679721b 100644
--- a/crates/json/lib.rs
+++ b/crates/json/lib.rs
@@ -139,7 +139,7 @@ impl slog_stream::Format for Format {
 
         let io = {
             let serializer = serde_json::Serializer::new(io);
-            let mut serializer = try!(SerdeSerializer::start(serializer));
+            let mut serializer = try!(SerdeSerializer::start(serializer, None));
 
             for (ref k, ref v) in self.values.iter() {
                 try!(v.serialize(rinfo, k, &mut serializer));
diff --git a/crates/serde/lib.rs b/crates/serde/lib.rs
index b22f95c80..22d829086 100644
--- a/crates/serde/lib.rs
+++ b/crates/serde/lib.rs
@@ -33,9 +33,9 @@ pub struct SerdeSerializer<S: serde::Serializer>{
 impl<S: serde::Serializer> SerdeSerializer<S> {
 
     /// Start serializing map of values
-    pub fn start(mut ser : S) -> result::Result<Self, ser::Error> {
+    pub fn start(mut ser : S, len: Option<usize>) -> result::Result<Self, ser::Error> {
         let map_state = try!(
-            ser.serialize_map(None)
+            ser.serialize_map(len)
                 .map_err(|_| io::Error::new(io::ErrorKind::Other, "serde serialization error"))
         );
         Ok(SerdeSerializer {


Test patch: