diff options
author | 2021-08-08 18:43:09 +0100 | |
---|---|---|
committer | 2021-08-09 02:43:09 +0900 | |
commit | fa9cbf1258cea7812d4009639ed8700b987d8d4e (patch) | |
tree | 875e95d7c312543b86582e648a50f84bed9f1b17 /src | |
parent | ab8e3c01a8fae128971cea43eca18da03482cb29 (diff) | |
download | bytes-fa9cbf1258cea7812d4009639ed8700b987d8d4e.tar.gz bytes-fa9cbf1258cea7812d4009639ed8700b987d8d4e.tar.zst bytes-fa9cbf1258cea7812d4009639ed8700b987d8d4e.zip |
Clarify BufPut::put_int behavior (#486)
* writes low bytes, discards high bytes
* panics if `nbytes` is greater than 8
Diffstat (limited to 'src')
-rw-r--r-- | src/buf/buf_mut.rs | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/buf/buf_mut.rs b/src/buf/buf_mut.rs index bf33fe6..b946658 100644 --- a/src/buf/buf_mut.rs +++ b/src/buf/buf_mut.rs @@ -703,7 +703,7 @@ pub unsafe trait BufMut { self.put_slice(&n.to_le_bytes()[0..nbytes]); } - /// Writes a signed n-byte integer to `self` in big-endian byte order. + /// Writes low `nbytes` of a signed integer to `self` in big-endian byte order. /// /// The current position is advanced by `nbytes`. /// @@ -713,19 +713,19 @@ pub unsafe trait BufMut { /// use bytes::BufMut; /// /// let mut buf = vec![]; - /// buf.put_int(0x010203, 3); + /// buf.put_int(0x0504010203, 3); /// assert_eq!(buf, b"\x01\x02\x03"); /// ``` /// /// # Panics /// /// This function panics if there is not enough remaining capacity in - /// `self`. + /// `self` or if `nbytes` is greater than 8. fn put_int(&mut self, n: i64, nbytes: usize) { self.put_slice(&n.to_be_bytes()[mem::size_of_val(&n) - nbytes..]); } - /// Writes a signed n-byte integer to `self` in little-endian byte order. + /// Writes low `nbytes` of a signed integer to `self` in little-endian byte order. /// /// The current position is advanced by `nbytes`. /// @@ -735,14 +735,14 @@ pub unsafe trait BufMut { /// use bytes::BufMut; /// /// let mut buf = vec![]; - /// buf.put_int_le(0x010203, 3); + /// buf.put_int_le(0x0504010203, 3); /// assert_eq!(buf, b"\x03\x02\x01"); /// ``` /// /// # Panics /// /// This function panics if there is not enough remaining capacity in - /// `self`. + /// `self` or if `nbytes` is greater than 8. fn put_int_le(&mut self, n: i64, nbytes: usize) { self.put_slice(&n.to_le_bytes()[0..nbytes]); } |