From 4645f6ec4bd607031d8899b1a36722b63ee4ed57 Mon Sep 17 00:00:00 2001
From: Sean McArthur <sean.monstar@gmail.com>
Date: Thu, 6 Apr 2017 08:59:13 -0700
Subject: [PATCH] implement put_u8 for BytesMut (#101)

---
 src/bytes.rs | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/src/bytes.rs b/src/bytes.rs
index 20af871..edc2e3a 100644
--- a/src/bytes.rs
+++ b/src/bytes.rs
@@ -1164,6 +1164,16 @@ impl BufMut for BytesMut {
             self.advance_mut(len);
         }
     }
+
+    #[inline]
+    fn put_u8(&mut self, n: u8) {
+        self.inner.put_u8(n);
+    }
+
+    #[inline]
+    fn put_i8(&mut self, n: i8) {
+        self.put_u8(n as u8);
+    }
 }
 
 impl IntoBuf for BytesMut {
@@ -1463,6 +1473,25 @@ impl Inner {
         }
     }
 
+    /// Insert a byte into the next slot and advance the len by 1.
+    #[inline]
+    fn put_u8(&mut self, n: u8) {
+        if self.is_inline() {
+            let len = self.inline_len();
+            assert!(len < INLINE_CAP);
+            unsafe {
+                *self.inline_ptr().offset(len as isize) = n;
+            }
+            self.set_inline_len(len + 1);
+        } else {
+            assert!(self.len < self.cap);
+            unsafe {
+                *self.ptr.offset(self.len as isize) = n;
+            }
+            self.len += 1;
+        }
+    }
+
     #[inline]
     fn len(&self) -> usize {
         if self.is_inline() {
-- 
GitLab