From 6dacc75b1abda0733185af96dc86cf677d6f0374 Mon Sep 17 00:00:00 2001 From: Jan Niehusmann Date: Sat, 18 Mar 2017 15:03:21 +0100 Subject: [PATCH] Reserve BytesMut size in encode. BytesMut::put panics if not enough free space is available. As Encoder::encode should not panic, call BytesMut::reserve before calling BytesMut::put. --- tests/simple_client_proto.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/simple_client_proto.rs b/tests/simple_client_proto.rs index 27f57e30..8b742a38 100644 --- a/tests/simple_client_proto.rs +++ b/tests/simple_client_proto.rs @@ -70,7 +70,9 @@ impl Encoder for IntCodec { type Error = io::Error; fn encode(&mut self, item: u64, into: &mut BytesMut) -> io::Result<()> { - into.put(item.to_string().as_bytes()); + let string = item.to_string(); + into.reserve(string.as_bytes().len()); + into.put(string.as_bytes()); Ok(()) } }