Bug 1806766 - Update bytes to 1.3.0. r=emilio,supply-chain-reviewers

Differential Revision: https://phabricator.services.mozilla.com/D165263
This commit is contained in:
Mike Hommey 2022-12-21 21:30:44 +00:00
Родитель 56ad65f73c
Коммит 908ac2ed86
10 изменённых файлов: 759 добавлений и 33 удалений

30
Cargo.lock сгенерированный
Просмотреть файл

@ -333,7 +333,7 @@ dependencies = [
"audio_thread_priority",
"bincode",
"byteorder",
"bytes 1.2.1",
"bytes 1.3.0",
"cc",
"crossbeam-channel",
"cubeb",
@ -627,9 +627,9 @@ dependencies = [
[[package]]
name = "bytes"
version = "1.2.1"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec8a7b6a70fde80372154c65702f00a0f56f3e1c36abbc6c440484be248856db"
checksum = "dfb24e866b15a1af2a1b663f10c6b6b8f397a84aadb828f12e5b289ec23a3a3c"
[[package]]
name = "cache-padded"
@ -2445,7 +2445,7 @@ version = "0.3.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5ca32592cf21ac7ccab1825cd87f6c9b3d9022c44d086172ed0966bec8af30be"
dependencies = [
"bytes 1.2.1",
"bytes 1.3.0",
"fnv",
"futures-core",
"futures-sink",
@ -2490,7 +2490,7 @@ checksum = "4cff78e5788be1e0ab65b04d306b2ed5092c815ec97ec70f4ebd5aee158aa55d"
dependencies = [
"base64",
"bitflags",
"bytes 1.2.1",
"bytes 1.3.0",
"headers-core",
"http",
"httpdate",
@ -2543,7 +2543,7 @@ version = "0.2.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "75f43d41e26995c17e71ee126451dd3941010b0514a81a9d11f3b341debc2399"
dependencies = [
"bytes 1.2.1",
"bytes 1.3.0",
"fnv",
"itoa",
]
@ -2554,7 +2554,7 @@ version = "0.4.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d5f38f16d184e36f2408a55281cd658ecbd3ca05cce6d6510a176eca393e26d1"
dependencies = [
"bytes 1.2.1",
"bytes 1.3.0",
"http",
"pin-project-lite",
]
@ -2610,7 +2610,7 @@ version = "0.14.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "02c929dc5c39e335a03c405292728118860721b10190d98c2a0f0efd5baafbac"
dependencies = [
"bytes 1.2.1",
"bytes 1.3.0",
"futures-channel",
"futures-core",
"futures-util",
@ -4318,7 +4318,7 @@ version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "de5e2533f59d08fcf364fd374ebda0692a70bd6d7e66ef97f306f45c6c5d8020"
dependencies = [
"bytes 1.2.1",
"bytes 1.3.0",
"prost-derive",
]
@ -5407,7 +5407,7 @@ version = "1.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2af73ac49756f3f7c01172e34a23e5d0216f6c32333757c2c61feb2bbff5a5ee"
dependencies = [
"bytes 1.2.1",
"bytes 1.3.0",
"libc",
"memchr",
"mio 0.8.0",
@ -5527,7 +5527,7 @@ version = "0.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f988a1a1adc2fb21f9c12aa96441da33a1728193ae0b95d2be22dbd17fcb4e5c"
dependencies = [
"bytes 1.2.1",
"bytes 1.3.0",
"futures-core",
"futures-sink",
"pin-project-lite",
@ -5747,7 +5747,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b983553c0d1ad73547c65fa0c399aa800bee4a70ad330198e1c7a523212da5ee"
dependencies = [
"anyhow",
"bytes 1.2.1",
"bytes 1.3.0",
"camino",
"cargo_metadata",
"log",
@ -5789,7 +5789,7 @@ name = "uniffi-example-custom-types"
version = "0.19.6"
dependencies = [
"anyhow",
"bytes 1.2.1",
"bytes 1.3.0",
"serde_json",
"uniffi",
"uniffi_build",
@ -6019,7 +6019,7 @@ version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3cef4e1e9114a4b7f1ac799f16ce71c14de5778500c5450ec6b7b920c55b587e"
dependencies = [
"bytes 1.2.1",
"bytes 1.3.0",
"futures-channel",
"futures-util",
"headers",
@ -6111,7 +6111,7 @@ name = "webdriver"
version = "0.47.0"
dependencies = [
"base64",
"bytes 1.2.1",
"bytes 1.3.0",
"cookie",
"http",
"log",

Просмотреть файл

@ -211,6 +211,11 @@ who = "Mike Hommey <mh+mozilla@glandium.org>"
criteria = "safe-to-deploy"
delta = "1.1.0 -> 1.2.1"
[[audits.bytes]]
who = "Mike Hommey <mh+mozilla@glandium.org>"
criteria = "safe-to-deploy"
delta = "1.2.1 -> 1.3.0"
[[audits.camino]]
who = "Mike Hommey <mh+mozilla@glandium.org>"
criteria = "safe-to-deploy"

2
third_party/rust/bytes/.cargo-checksum.json поставляемый
Просмотреть файл

@ -1 +1 @@
{"files":{"CHANGELOG.md":"f6e9c0188bb3dea02b2db80c9a3b9bef263de53fa51303b7e3b5297e14cb2b4a","Cargo.toml":"6549e17368b94b0c93696b62a151587b8ef8879d282c4784cdc85cc1862ee242","LICENSE":"45f522cacecb1023856e46df79ca625dfc550c94910078bd8aec6e02880b3d42","README.md":"b691d6e144eb133c181e869dc2f6a6eedbf76c4f832a9ecfbed5b9c560160c7f","benches/buf.rs":"72e6b6120b52d568da068f17c66a793d65602e400c595778581b63092e41d8dc","benches/bytes.rs":"f8cc255be7e8afedf6ade95cd529d105c537c5ec51110d46d470a26b497afa05","benches/bytes_mut.rs":"1326fe6224b26826228e02b4133151e756f38152c2d9cfe66adf83af76c3ec98","ci/miri.sh":"1ee54575b55a0e495e52ca1a934beed674bc8f375f03c4cfc3e81d221ec4fe98","ci/test-stable.sh":"57dd709bc25a20103ee85e24965566900817b2e603f067fb1251a5c03e4b1d93","ci/tsan.sh":"466b86b19225dd26c756cf2252cb1973f87a145642c99364b462ed7ceb55c7dd","clippy.toml":"8522f448dfa3b33ac334ce47d233ebb6b58e8ae115e45107a64fc1b4510fe560","src/buf/buf_impl.rs":"bdd9d5bc3318185ef1bea8d7c6a9dd3712ec297e0045fd84024f188c0ad96ac0","src/buf/buf_mut.rs":"58d9a82d982b2fc4c5421beafd31a9d0ea1ae500fd4a8b469ffc22e5bb21822a","src/buf/chain.rs":"46ec16a7cc370374218c2621ad738df77d95b25216099900ad9195a08a234375","src/buf/iter.rs":"49e9990a2303252ef7c66c2cc24459097dbbf4900c978453982ef513467bbf67","src/buf/limit.rs":"e005ba140b70f68654877c96b981a220477e415ff5c92438c1b0cb9bc866d872","src/buf/mod.rs":"19ff6fb7e19cba3884bc3f1a50ef20117dbc807f6d146ed355f42344a74fdf44","src/buf/reader.rs":"856c1e7129a1eceaa3c8f9ed4da8c3b5e1cc267eeffa99fa8f7c56c5ca7834d1","src/buf/take.rs":"a897e79bf579391227816973b2aa1f1d63614bd48bc029d9371f61607dcfa23f","src/buf/uninit_slice.rs":"b3bc013336235de246ddcb87f2961c556e800851d2199f4326a7b466c566b4a0","src/buf/vec_deque.rs":"8d552c26ac6ce28a471f74c388e4749432e86b1d8f5a9759b9fc32a2549d395f","src/buf/writer.rs":"c92b5f8b9b42e2e784de474c987fe4ac50af4b5c51ac9548d19a54e8ac9ff521","src/bytes.rs":"37b2df8bc94560d6a6ba2fbfb702358686d5b016cd7d48c80f51fa2ad03c5393","src/bytes_mut.rs":"29854cf9fbedd12ca66cf76bf4b1ca4424620ad495c75243a51a77efda926c73","src/fmt/debug.rs":"97b23cfa1d2701fa187005421302eeb260e635cd4f9a9e02b044ff89fcc8b8ad","src/fmt/hex.rs":"13755ec6f1b79923e1f1a05c51b179a38c03c40bb8ed2db0210e8901812e61e7","src/fmt/mod.rs":"176da4e359da99b8e5cf16e480cb7b978f574876827f1b9bb9c08da4d74ac0f5","src/lib.rs":"d8be90ade0cf78a30d73493086c109049d8ff442d69589a07f16480578eb4b17","src/loom.rs":"eb3f577d8cce39a84155c241c4dc308f024631f02085833f7fe9f0ea817bcea9","src/serde.rs":"3ecd7e828cd4c2b7db93c807cb1548fad209e674df493edf7cda69a7b04d405d","tests/test_buf.rs":"a04fb90644fcf0444092c49a4ca848bb0fd8b2ffeeebcb705eeea2de58560859","tests/test_buf_mut.rs":"5643866cd7b0967fb36053a1da73a23b26ffaa2746c05dca91e82df91aee7f81","tests/test_bytes.rs":"fe5beb749d3d48ec0c57d2ecf0ca56edc5a08cdc07a7842d863ee64d78d0ce69","tests/test_bytes_odd_alloc.rs":"aeb7a86bf8b31f67b6f453399f3649e0d3878247debc1325d98e66201b1da15f","tests/test_bytes_vec_alloc.rs":"dd7e3c3a71abcfdcad7e3b2f52a6bd106ad6ea0d4bc634372e81dae097233cf0","tests/test_chain.rs":"e9f094539bb42b3135f50033c44122a6b44cf0f953e51e8b488f43243f1e7f10","tests/test_debug.rs":"13299107172809e8cbbd823964ac9450cd0d6b6de79f2e6a2e0f44b9225a0593","tests/test_iter.rs":"c1f46823df26a90139645fd8728a03138edd95b2849dfec830452a80ddd9726d","tests/test_reader.rs":"bf83669d4e0960dad6aa47b46a9a454814fab626eb83572aba914c3d71618f43","tests/test_serde.rs":"2691f891796ba259de0ecf926de05c514f4912cc5fcd3e6a1591efbcd23ed4d0","tests/test_take.rs":"db01bf6855097f318336e90d12c0725a92cee426d330e477a6bd1d32dac34a27"},"package":"ec8a7b6a70fde80372154c65702f00a0f56f3e1c36abbc6c440484be248856db"}
{"files":{"CHANGELOG.md":"f0a59a40feba4e8949867f78306369b348f173a30103242fc6b56ccd695164a2","Cargo.toml":"4241f067d731580f52f81d6af804ec4c8d5ff2e67a4fc6144732eb465f48cadf","LICENSE":"45f522cacecb1023856e46df79ca625dfc550c94910078bd8aec6e02880b3d42","README.md":"b691d6e144eb133c181e869dc2f6a6eedbf76c4f832a9ecfbed5b9c560160c7f","benches/buf.rs":"72e6b6120b52d568da068f17c66a793d65602e400c595778581b63092e41d8dc","benches/bytes.rs":"f8cc255be7e8afedf6ade95cd529d105c537c5ec51110d46d470a26b497afa05","benches/bytes_mut.rs":"1326fe6224b26826228e02b4133151e756f38152c2d9cfe66adf83af76c3ec98","ci/miri.sh":"1ee54575b55a0e495e52ca1a934beed674bc8f375f03c4cfc3e81d221ec4fe98","ci/test-stable.sh":"57dd709bc25a20103ee85e24965566900817b2e603f067fb1251a5c03e4b1d93","ci/tsan.sh":"466b86b19225dd26c756cf2252cb1973f87a145642c99364b462ed7ceb55c7dd","clippy.toml":"8522f448dfa3b33ac334ce47d233ebb6b58e8ae115e45107a64fc1b4510fe560","src/buf/buf_impl.rs":"b8d501d3d9c887336560bbe1c334f3f1b33d9c3e973b727f3928f265c08a8fd5","src/buf/buf_mut.rs":"88ea083992db5afba46b609d70fe73fc3959d96c99973cf4a6863a21874b80b6","src/buf/chain.rs":"46ec16a7cc370374218c2621ad738df77d95b25216099900ad9195a08a234375","src/buf/iter.rs":"49e9990a2303252ef7c66c2cc24459097dbbf4900c978453982ef513467bbf67","src/buf/limit.rs":"e005ba140b70f68654877c96b981a220477e415ff5c92438c1b0cb9bc866d872","src/buf/mod.rs":"19ff6fb7e19cba3884bc3f1a50ef20117dbc807f6d146ed355f42344a74fdf44","src/buf/reader.rs":"856c1e7129a1eceaa3c8f9ed4da8c3b5e1cc267eeffa99fa8f7c56c5ca7834d1","src/buf/take.rs":"a897e79bf579391227816973b2aa1f1d63614bd48bc029d9371f61607dcfa23f","src/buf/uninit_slice.rs":"fccd4e90f5b4f7eb7774e10d7da0838952e4ddc5b324301d37bb7680eac26e36","src/buf/vec_deque.rs":"8d552c26ac6ce28a471f74c388e4749432e86b1d8f5a9759b9fc32a2549d395f","src/buf/writer.rs":"c92b5f8b9b42e2e784de474c987fe4ac50af4b5c51ac9548d19a54e8ac9ff521","src/bytes.rs":"e6a3cb50ec50ca026137f0f23a912b7fe8a5d77a826b2ae7e6df866b9196114d","src/bytes_mut.rs":"64fe05016fef2cbaa5b0b3d0d01279b99ad0ecc6d9ed99ce27e43fe9c6b2844b","src/fmt/debug.rs":"97b23cfa1d2701fa187005421302eeb260e635cd4f9a9e02b044ff89fcc8b8ad","src/fmt/hex.rs":"13755ec6f1b79923e1f1a05c51b179a38c03c40bb8ed2db0210e8901812e61e7","src/fmt/mod.rs":"176da4e359da99b8e5cf16e480cb7b978f574876827f1b9bb9c08da4d74ac0f5","src/lib.rs":"d8be90ade0cf78a30d73493086c109049d8ff442d69589a07f16480578eb4b17","src/loom.rs":"eb3f577d8cce39a84155c241c4dc308f024631f02085833f7fe9f0ea817bcea9","src/serde.rs":"3ecd7e828cd4c2b7db93c807cb1548fad209e674df493edf7cda69a7b04d405d","tests/test_buf.rs":"a04fb90644fcf0444092c49a4ca848bb0fd8b2ffeeebcb705eeea2de58560859","tests/test_buf_mut.rs":"5643866cd7b0967fb36053a1da73a23b26ffaa2746c05dca91e82df91aee7f81","tests/test_bytes.rs":"fe5beb749d3d48ec0c57d2ecf0ca56edc5a08cdc07a7842d863ee64d78d0ce69","tests/test_bytes_odd_alloc.rs":"aeb7a86bf8b31f67b6f453399f3649e0d3878247debc1325d98e66201b1da15f","tests/test_bytes_vec_alloc.rs":"dd7e3c3a71abcfdcad7e3b2f52a6bd106ad6ea0d4bc634372e81dae097233cf0","tests/test_chain.rs":"e9f094539bb42b3135f50033c44122a6b44cf0f953e51e8b488f43243f1e7f10","tests/test_debug.rs":"13299107172809e8cbbd823964ac9450cd0d6b6de79f2e6a2e0f44b9225a0593","tests/test_iter.rs":"c1f46823df26a90139645fd8728a03138edd95b2849dfec830452a80ddd9726d","tests/test_reader.rs":"bf83669d4e0960dad6aa47b46a9a454814fab626eb83572aba914c3d71618f43","tests/test_serde.rs":"2691f891796ba259de0ecf926de05c514f4912cc5fcd3e6a1591efbcd23ed4d0","tests/test_take.rs":"db01bf6855097f318336e90d12c0725a92cee426d330e477a6bd1d32dac34a27"},"package":"dfb24e866b15a1af2a1b663f10c6b6b8f397a84aadb828f12e5b289ec23a3a3c"}

15
third_party/rust/bytes/CHANGELOG.md поставляемый
Просмотреть файл

@ -1,3 +1,18 @@
# 1.3.0 (November 20, 2022)
### Added
- Rename and expose `BytesMut::spare_capacity_mut` (#572)
- Implement native-endian get and put functions for `Buf` and `BufMut` (#576)
### Fixed
- Don't have important data in unused capacity when calling reserve (#563)
### Documented
- `Bytes::new` etc should return `Self` not `Bytes` (#568)
# 1.2.1 (July 30, 2022)
### Fixed

2
third_party/rust/bytes/Cargo.toml поставляемый
Просмотреть файл

@ -12,7 +12,7 @@
[package]
edition = "2018"
name = "bytes"
version = "1.2.1"
version = "1.3.0"
authors = [
"Carl Lerche <me@carllerche.com>",
"Sean McArthur <sean@seanmonstar.com>",

318
third_party/rust/bytes/src/buf/buf_impl.rs поставляемый
Просмотреть файл

@ -354,6 +354,29 @@ pub trait Buf {
buf_get_impl!(self, u16::from_le_bytes);
}
/// Gets an unsigned 16 bit integer from `self` in native-endian byte order.
///
/// The current position is advanced by 2.
///
/// # Examples
///
/// ```
/// use bytes::Buf;
///
/// let mut buf: &[u8] = match cfg!(target_endian = "big") {
/// true => b"\x08\x09 hello",
/// false => b"\x09\x08 hello",
/// };
/// assert_eq!(0x0809, buf.get_u16_ne());
/// ```
///
/// # Panics
///
/// This function panics if there is not enough remaining data in `self`.
fn get_u16_ne(&mut self) -> u16 {
buf_get_impl!(self, u16::from_ne_bytes);
}
/// Gets a signed 16 bit integer from `self` in big-endian byte order.
///
/// The current position is advanced by 2.
@ -394,6 +417,29 @@ pub trait Buf {
buf_get_impl!(self, i16::from_le_bytes);
}
/// Gets a signed 16 bit integer from `self` in native-endian byte order.
///
/// The current position is advanced by 2.
///
/// # Examples
///
/// ```
/// use bytes::Buf;
///
/// let mut buf: &[u8] = match cfg!(target_endian = "big") {
/// true => b"\x08\x09 hello",
/// false => b"\x09\x08 hello",
/// };
/// assert_eq!(0x0809, buf.get_i16_ne());
/// ```
///
/// # Panics
///
/// This function panics if there is not enough remaining data in `self`.
fn get_i16_ne(&mut self) -> i16 {
buf_get_impl!(self, i16::from_ne_bytes);
}
/// Gets an unsigned 32 bit integer from `self` in the big-endian byte order.
///
/// The current position is advanced by 4.
@ -434,6 +480,29 @@ pub trait Buf {
buf_get_impl!(self, u32::from_le_bytes);
}
/// Gets an unsigned 32 bit integer from `self` in native-endian byte order.
///
/// The current position is advanced by 4.
///
/// # Examples
///
/// ```
/// use bytes::Buf;
///
/// let mut buf: &[u8] = match cfg!(target_endian = "big") {
/// true => b"\x08\x09\xA0\xA1 hello",
/// false => b"\xA1\xA0\x09\x08 hello",
/// };
/// assert_eq!(0x0809A0A1, buf.get_u32_ne());
/// ```
///
/// # Panics
///
/// This function panics if there is not enough remaining data in `self`.
fn get_u32_ne(&mut self) -> u32 {
buf_get_impl!(self, u32::from_ne_bytes);
}
/// Gets a signed 32 bit integer from `self` in big-endian byte order.
///
/// The current position is advanced by 4.
@ -474,6 +543,29 @@ pub trait Buf {
buf_get_impl!(self, i32::from_le_bytes);
}
/// Gets a signed 32 bit integer from `self` in native-endian byte order.
///
/// The current position is advanced by 4.
///
/// # Examples
///
/// ```
/// use bytes::Buf;
///
/// let mut buf: &[u8] = match cfg!(target_endian = "big") {
/// true => b"\x08\x09\xA0\xA1 hello",
/// false => b"\xA1\xA0\x09\x08 hello",
/// };
/// assert_eq!(0x0809A0A1, buf.get_i32_ne());
/// ```
///
/// # Panics
///
/// This function panics if there is not enough remaining data in `self`.
fn get_i32_ne(&mut self) -> i32 {
buf_get_impl!(self, i32::from_ne_bytes);
}
/// Gets an unsigned 64 bit integer from `self` in big-endian byte order.
///
/// The current position is advanced by 8.
@ -514,6 +606,29 @@ pub trait Buf {
buf_get_impl!(self, u64::from_le_bytes);
}
/// Gets an unsigned 64 bit integer from `self` in native-endian byte order.
///
/// The current position is advanced by 8.
///
/// # Examples
///
/// ```
/// use bytes::Buf;
///
/// let mut buf: &[u8] = match cfg!(target_endian = "big") {
/// true => b"\x01\x02\x03\x04\x05\x06\x07\x08 hello",
/// false => b"\x08\x07\x06\x05\x04\x03\x02\x01 hello",
/// };
/// assert_eq!(0x0102030405060708, buf.get_u64_ne());
/// ```
///
/// # Panics
///
/// This function panics if there is not enough remaining data in `self`.
fn get_u64_ne(&mut self) -> u64 {
buf_get_impl!(self, u64::from_ne_bytes);
}
/// Gets a signed 64 bit integer from `self` in big-endian byte order.
///
/// The current position is advanced by 8.
@ -554,6 +669,29 @@ pub trait Buf {
buf_get_impl!(self, i64::from_le_bytes);
}
/// Gets a signed 64 bit integer from `self` in native-endian byte order.
///
/// The current position is advanced by 8.
///
/// # Examples
///
/// ```
/// use bytes::Buf;
///
/// let mut buf: &[u8] = match cfg!(target_endian = "big") {
/// true => b"\x01\x02\x03\x04\x05\x06\x07\x08 hello",
/// false => b"\x08\x07\x06\x05\x04\x03\x02\x01 hello",
/// };
/// assert_eq!(0x0102030405060708, buf.get_i64_ne());
/// ```
///
/// # Panics
///
/// This function panics if there is not enough remaining data in `self`.
fn get_i64_ne(&mut self) -> i64 {
buf_get_impl!(self, i64::from_ne_bytes);
}
/// Gets an unsigned 128 bit integer from `self` in big-endian byte order.
///
/// The current position is advanced by 16.
@ -594,6 +732,29 @@ pub trait Buf {
buf_get_impl!(self, u128::from_le_bytes);
}
/// Gets an unsigned 128 bit integer from `self` in native-endian byte order.
///
/// The current position is advanced by 16.
///
/// # Examples
///
/// ```
/// use bytes::Buf;
///
/// let mut buf: &[u8] = match cfg!(target_endian = "big") {
/// true => b"\x01\x02\x03\x04\x05\x06\x07\x08\x09\x10\x11\x12\x13\x14\x15\x16 hello",
/// false => b"\x16\x15\x14\x13\x12\x11\x10\x09\x08\x07\x06\x05\x04\x03\x02\x01 hello",
/// };
/// assert_eq!(0x01020304050607080910111213141516, buf.get_u128_ne());
/// ```
///
/// # Panics
///
/// This function panics if there is not enough remaining data in `self`.
fn get_u128_ne(&mut self) -> u128 {
buf_get_impl!(self, u128::from_ne_bytes);
}
/// Gets a signed 128 bit integer from `self` in big-endian byte order.
///
/// The current position is advanced by 16.
@ -634,6 +795,29 @@ pub trait Buf {
buf_get_impl!(self, i128::from_le_bytes);
}
/// Gets a signed 128 bit integer from `self` in native-endian byte order.
///
/// The current position is advanced by 16.
///
/// # Examples
///
/// ```
/// use bytes::Buf;
///
/// let mut buf: &[u8] = match cfg!(target_endian = "big") {
/// true => b"\x01\x02\x03\x04\x05\x06\x07\x08\x09\x10\x11\x12\x13\x14\x15\x16 hello",
/// false => b"\x16\x15\x14\x13\x12\x11\x10\x09\x08\x07\x06\x05\x04\x03\x02\x01 hello",
/// };
/// assert_eq!(0x01020304050607080910111213141516, buf.get_i128_ne());
/// ```
///
/// # Panics
///
/// This function panics if there is not enough remaining data in `self`.
fn get_i128_ne(&mut self) -> i128 {
buf_get_impl!(self, i128::from_ne_bytes);
}
/// Gets an unsigned n-byte integer from `self` in big-endian byte order.
///
/// The current position is advanced by `nbytes`.
@ -674,6 +858,33 @@ pub trait Buf {
buf_get_impl!(le => self, u64, nbytes);
}
/// Gets an unsigned n-byte integer from `self` in native-endian byte order.
///
/// The current position is advanced by `nbytes`.
///
/// # Examples
///
/// ```
/// use bytes::Buf;
///
/// let mut buf: &[u8] = match cfg!(target_endian = "big") {
/// true => b"\x01\x02\x03 hello",
/// false => b"\x03\x02\x01 hello",
/// };
/// assert_eq!(0x010203, buf.get_uint_ne(3));
/// ```
///
/// # Panics
///
/// This function panics if there is not enough remaining data in `self`.
fn get_uint_ne(&mut self, nbytes: usize) -> u64 {
if cfg!(target_endian = "big") {
self.get_uint(nbytes)
} else {
self.get_uint_le(nbytes)
}
}
/// Gets a signed n-byte integer from `self` in big-endian byte order.
///
/// The current position is advanced by `nbytes`.
@ -714,6 +925,33 @@ pub trait Buf {
buf_get_impl!(le => self, i64, nbytes);
}
/// Gets a signed n-byte integer from `self` in native-endian byte order.
///
/// The current position is advanced by `nbytes`.
///
/// # Examples
///
/// ```
/// use bytes::Buf;
///
/// let mut buf: &[u8] = match cfg!(target_endian = "big") {
/// true => b"\x01\x02\x03 hello",
/// false => b"\x03\x02\x01 hello",
/// };
/// assert_eq!(0x010203, buf.get_int_ne(3));
/// ```
///
/// # Panics
///
/// This function panics if there is not enough remaining data in `self`.
fn get_int_ne(&mut self, nbytes: usize) -> i64 {
if cfg!(target_endian = "big") {
self.get_int(nbytes)
} else {
self.get_int_le(nbytes)
}
}
/// Gets an IEEE754 single-precision (4 bytes) floating point number from
/// `self` in big-endian byte order.
///
@ -756,6 +994,30 @@ pub trait Buf {
f32::from_bits(Self::get_u32_le(self))
}
/// Gets an IEEE754 single-precision (4 bytes) floating point number from
/// `self` in native-endian byte order.
///
/// The current position is advanced by 4.
///
/// # Examples
///
/// ```
/// use bytes::Buf;
///
/// let mut buf: &[u8] = match cfg!(target_endian = "big") {
/// true => b"\x3F\x99\x99\x9A hello",
/// false => b"\x9A\x99\x99\x3F hello",
/// };
/// assert_eq!(1.2f32, buf.get_f32_ne());
/// ```
///
/// # Panics
///
/// This function panics if there is not enough remaining data in `self`.
fn get_f32_ne(&mut self) -> f32 {
f32::from_bits(Self::get_u32_ne(self))
}
/// Gets an IEEE754 double-precision (8 bytes) floating point number from
/// `self` in big-endian byte order.
///
@ -798,6 +1060,30 @@ pub trait Buf {
f64::from_bits(Self::get_u64_le(self))
}
/// Gets an IEEE754 double-precision (8 bytes) floating point number from
/// `self` in native-endian byte order.
///
/// The current position is advanced by 8.
///
/// # Examples
///
/// ```
/// use bytes::Buf;
///
/// let mut buf: &[u8] = match cfg!(target_endian = "big") {
/// true => b"\x3F\xF3\x33\x33\x33\x33\x33\x33 hello",
/// false => b"\x33\x33\x33\x33\x33\x33\xF3\x3F hello",
/// };
/// assert_eq!(1.2f64, buf.get_f64_ne());
/// ```
///
/// # Panics
///
/// This function panics if there is not enough remaining data in `self`.
fn get_f64_ne(&mut self) -> f64 {
f64::from_bits(Self::get_u64_ne(self))
}
/// Consumes `len` bytes inside self and returns new instance of `Bytes`
/// with this data.
///
@ -948,6 +1234,10 @@ macro_rules! deref_forward_buf {
(**self).get_u16_le()
}
fn get_u16_ne(&mut self) -> u16 {
(**self).get_u16_ne()
}
fn get_i16(&mut self) -> i16 {
(**self).get_i16()
}
@ -956,6 +1246,10 @@ macro_rules! deref_forward_buf {
(**self).get_i16_le()
}
fn get_i16_ne(&mut self) -> i16 {
(**self).get_i16_ne()
}
fn get_u32(&mut self) -> u32 {
(**self).get_u32()
}
@ -964,6 +1258,10 @@ macro_rules! deref_forward_buf {
(**self).get_u32_le()
}
fn get_u32_ne(&mut self) -> u32 {
(**self).get_u32_ne()
}
fn get_i32(&mut self) -> i32 {
(**self).get_i32()
}
@ -972,6 +1270,10 @@ macro_rules! deref_forward_buf {
(**self).get_i32_le()
}
fn get_i32_ne(&mut self) -> i32 {
(**self).get_i32_ne()
}
fn get_u64(&mut self) -> u64 {
(**self).get_u64()
}
@ -980,6 +1282,10 @@ macro_rules! deref_forward_buf {
(**self).get_u64_le()
}
fn get_u64_ne(&mut self) -> u64 {
(**self).get_u64_ne()
}
fn get_i64(&mut self) -> i64 {
(**self).get_i64()
}
@ -988,6 +1294,10 @@ macro_rules! deref_forward_buf {
(**self).get_i64_le()
}
fn get_i64_ne(&mut self) -> i64 {
(**self).get_i64_ne()
}
fn get_uint(&mut self, nbytes: usize) -> u64 {
(**self).get_uint(nbytes)
}
@ -996,6 +1306,10 @@ macro_rules! deref_forward_buf {
(**self).get_uint_le(nbytes)
}
fn get_uint_ne(&mut self, nbytes: usize) -> u64 {
(**self).get_uint_ne(nbytes)
}
fn get_int(&mut self, nbytes: usize) -> i64 {
(**self).get_int(nbytes)
}
@ -1004,6 +1318,10 @@ macro_rules! deref_forward_buf {
(**self).get_int_le(nbytes)
}
fn get_int_ne(&mut self, nbytes: usize) -> i64 {
(**self).get_int_ne(nbytes)
}
fn copy_to_bytes(&mut self, len: usize) -> crate::Bytes {
(**self).copy_to_bytes(len)
}

346
third_party/rust/bytes/src/buf/buf_mut.rs поставляемый
Просмотреть файл

@ -386,6 +386,32 @@ pub unsafe trait BufMut {
self.put_slice(&n.to_le_bytes())
}
/// Writes an unsigned 16 bit integer to `self` in native-endian byte order.
///
/// The current position is advanced by 2.
///
/// # Examples
///
/// ```
/// use bytes::BufMut;
///
/// let mut buf = vec![];
/// buf.put_u16_ne(0x0809);
/// if cfg!(target_endian = "big") {
/// assert_eq!(buf, b"\x08\x09");
/// } else {
/// assert_eq!(buf, b"\x09\x08");
/// }
/// ```
///
/// # Panics
///
/// This function panics if there is not enough remaining capacity in
/// `self`.
fn put_u16_ne(&mut self, n: u16) {
self.put_slice(&n.to_ne_bytes())
}
/// Writes a signed 16 bit integer to `self` in big-endian byte order.
///
/// The current position is advanced by 2.
@ -430,6 +456,32 @@ pub unsafe trait BufMut {
self.put_slice(&n.to_le_bytes())
}
/// Writes a signed 16 bit integer to `self` in native-endian byte order.
///
/// The current position is advanced by 2.
///
/// # Examples
///
/// ```
/// use bytes::BufMut;
///
/// let mut buf = vec![];
/// buf.put_i16_ne(0x0809);
/// if cfg!(target_endian = "big") {
/// assert_eq!(buf, b"\x08\x09");
/// } else {
/// assert_eq!(buf, b"\x09\x08");
/// }
/// ```
///
/// # Panics
///
/// This function panics if there is not enough remaining capacity in
/// `self`.
fn put_i16_ne(&mut self, n: i16) {
self.put_slice(&n.to_ne_bytes())
}
/// Writes an unsigned 32 bit integer to `self` in big-endian byte order.
///
/// The current position is advanced by 4.
@ -474,6 +526,32 @@ pub unsafe trait BufMut {
self.put_slice(&n.to_le_bytes())
}
/// Writes an unsigned 32 bit integer to `self` in native-endian byte order.
///
/// The current position is advanced by 4.
///
/// # Examples
///
/// ```
/// use bytes::BufMut;
///
/// let mut buf = vec![];
/// buf.put_u32_ne(0x0809A0A1);
/// if cfg!(target_endian = "big") {
/// assert_eq!(buf, b"\x08\x09\xA0\xA1");
/// } else {
/// assert_eq!(buf, b"\xA1\xA0\x09\x08");
/// }
/// ```
///
/// # Panics
///
/// This function panics if there is not enough remaining capacity in
/// `self`.
fn put_u32_ne(&mut self, n: u32) {
self.put_slice(&n.to_ne_bytes())
}
/// Writes a signed 32 bit integer to `self` in big-endian byte order.
///
/// The current position is advanced by 4.
@ -518,6 +596,32 @@ pub unsafe trait BufMut {
self.put_slice(&n.to_le_bytes())
}
/// Writes a signed 32 bit integer to `self` in native-endian byte order.
///
/// The current position is advanced by 4.
///
/// # Examples
///
/// ```
/// use bytes::BufMut;
///
/// let mut buf = vec![];
/// buf.put_i32_ne(0x0809A0A1);
/// if cfg!(target_endian = "big") {
/// assert_eq!(buf, b"\x08\x09\xA0\xA1");
/// } else {
/// assert_eq!(buf, b"\xA1\xA0\x09\x08");
/// }
/// ```
///
/// # Panics
///
/// This function panics if there is not enough remaining capacity in
/// `self`.
fn put_i32_ne(&mut self, n: i32) {
self.put_slice(&n.to_ne_bytes())
}
/// Writes an unsigned 64 bit integer to `self` in the big-endian byte order.
///
/// The current position is advanced by 8.
@ -562,6 +666,32 @@ pub unsafe trait BufMut {
self.put_slice(&n.to_le_bytes())
}
/// Writes an unsigned 64 bit integer to `self` in native-endian byte order.
///
/// The current position is advanced by 8.
///
/// # Examples
///
/// ```
/// use bytes::BufMut;
///
/// let mut buf = vec![];
/// buf.put_u64_ne(0x0102030405060708);
/// if cfg!(target_endian = "big") {
/// assert_eq!(buf, b"\x01\x02\x03\x04\x05\x06\x07\x08");
/// } else {
/// assert_eq!(buf, b"\x08\x07\x06\x05\x04\x03\x02\x01");
/// }
/// ```
///
/// # Panics
///
/// This function panics if there is not enough remaining capacity in
/// `self`.
fn put_u64_ne(&mut self, n: u64) {
self.put_slice(&n.to_ne_bytes())
}
/// Writes a signed 64 bit integer to `self` in the big-endian byte order.
///
/// The current position is advanced by 8.
@ -606,6 +736,32 @@ pub unsafe trait BufMut {
self.put_slice(&n.to_le_bytes())
}
/// Writes a signed 64 bit integer to `self` in native-endian byte order.
///
/// The current position is advanced by 8.
///
/// # Examples
///
/// ```
/// use bytes::BufMut;
///
/// let mut buf = vec![];
/// buf.put_i64_ne(0x0102030405060708);
/// if cfg!(target_endian = "big") {
/// assert_eq!(buf, b"\x01\x02\x03\x04\x05\x06\x07\x08");
/// } else {
/// assert_eq!(buf, b"\x08\x07\x06\x05\x04\x03\x02\x01");
/// }
/// ```
///
/// # Panics
///
/// This function panics if there is not enough remaining capacity in
/// `self`.
fn put_i64_ne(&mut self, n: i64) {
self.put_slice(&n.to_ne_bytes())
}
/// Writes an unsigned 128 bit integer to `self` in the big-endian byte order.
///
/// The current position is advanced by 16.
@ -650,6 +806,32 @@ pub unsafe trait BufMut {
self.put_slice(&n.to_le_bytes())
}
/// Writes an unsigned 128 bit integer to `self` in native-endian byte order.
///
/// The current position is advanced by 16.
///
/// # Examples
///
/// ```
/// use bytes::BufMut;
///
/// let mut buf = vec![];
/// buf.put_u128_ne(0x01020304050607080910111213141516);
/// if cfg!(target_endian = "big") {
/// assert_eq!(buf, b"\x01\x02\x03\x04\x05\x06\x07\x08\x09\x10\x11\x12\x13\x14\x15\x16");
/// } else {
/// assert_eq!(buf, b"\x16\x15\x14\x13\x12\x11\x10\x09\x08\x07\x06\x05\x04\x03\x02\x01");
/// }
/// ```
///
/// # Panics
///
/// This function panics if there is not enough remaining capacity in
/// `self`.
fn put_u128_ne(&mut self, n: u128) {
self.put_slice(&n.to_ne_bytes())
}
/// Writes a signed 128 bit integer to `self` in the big-endian byte order.
///
/// The current position is advanced by 16.
@ -694,6 +876,32 @@ pub unsafe trait BufMut {
self.put_slice(&n.to_le_bytes())
}
/// Writes a signed 128 bit integer to `self` in native-endian byte order.
///
/// The current position is advanced by 16.
///
/// # Examples
///
/// ```
/// use bytes::BufMut;
///
/// let mut buf = vec![];
/// buf.put_i128_ne(0x01020304050607080910111213141516);
/// if cfg!(target_endian = "big") {
/// assert_eq!(buf, b"\x01\x02\x03\x04\x05\x06\x07\x08\x09\x10\x11\x12\x13\x14\x15\x16");
/// } else {
/// assert_eq!(buf, b"\x16\x15\x14\x13\x12\x11\x10\x09\x08\x07\x06\x05\x04\x03\x02\x01");
/// }
/// ```
///
/// # Panics
///
/// This function panics if there is not enough remaining capacity in
/// `self`.
fn put_i128_ne(&mut self, n: i128) {
self.put_slice(&n.to_ne_bytes())
}
/// Writes an unsigned n-byte integer to `self` in big-endian byte order.
///
/// The current position is advanced by `nbytes`.
@ -738,6 +946,36 @@ pub unsafe trait BufMut {
self.put_slice(&n.to_le_bytes()[0..nbytes]);
}
/// Writes an unsigned n-byte integer to `self` in the native-endian byte order.
///
/// The current position is advanced by `nbytes`.
///
/// # Examples
///
/// ```
/// use bytes::BufMut;
///
/// let mut buf = vec![];
/// buf.put_uint_ne(0x010203, 3);
/// if cfg!(target_endian = "big") {
/// assert_eq!(buf, b"\x01\x02\x03");
/// } else {
/// assert_eq!(buf, b"\x03\x02\x01");
/// }
/// ```
///
/// # Panics
///
/// This function panics if there is not enough remaining capacity in
/// `self`.
fn put_uint_ne(&mut self, n: u64, nbytes: usize) {
if cfg!(target_endian = "big") {
self.put_uint(n, nbytes)
} else {
self.put_uint_le(n, nbytes)
}
}
/// Writes low `nbytes` of a signed integer to `self` in big-endian byte order.
///
/// The current position is advanced by `nbytes`.
@ -782,6 +1020,36 @@ pub unsafe trait BufMut {
self.put_slice(&n.to_le_bytes()[0..nbytes]);
}
/// Writes low `nbytes` of a signed integer to `self` in native-endian byte order.
///
/// The current position is advanced by `nbytes`.
///
/// # Examples
///
/// ```
/// use bytes::BufMut;
///
/// let mut buf = vec![];
/// buf.put_int_ne(0x010203, 3);
/// if cfg!(target_endian = "big") {
/// assert_eq!(buf, b"\x01\x02\x03");
/// } else {
/// assert_eq!(buf, b"\x03\x02\x01");
/// }
/// ```
///
/// # Panics
///
/// This function panics if there is not enough remaining capacity in
/// `self` or if `nbytes` is greater than 8.
fn put_int_ne(&mut self, n: i64, nbytes: usize) {
if cfg!(target_endian = "big") {
self.put_int(n, nbytes)
} else {
self.put_int_le(n, nbytes)
}
}
/// Writes an IEEE754 single-precision (4 bytes) floating point number to
/// `self` in big-endian byte order.
///
@ -828,6 +1096,33 @@ pub unsafe trait BufMut {
self.put_u32_le(n.to_bits());
}
/// Writes an IEEE754 single-precision (4 bytes) floating point number to
/// `self` in native-endian byte order.
///
/// The current position is advanced by 4.
///
/// # Examples
///
/// ```
/// use bytes::BufMut;
///
/// let mut buf = vec![];
/// buf.put_f32_ne(1.2f32);
/// if cfg!(target_endian = "big") {
/// assert_eq!(buf, b"\x3F\x99\x99\x9A");
/// } else {
/// assert_eq!(buf, b"\x9A\x99\x99\x3F");
/// }
/// ```
///
/// # Panics
///
/// This function panics if there is not enough remaining capacity in
/// `self`.
fn put_f32_ne(&mut self, n: f32) {
self.put_u32_ne(n.to_bits());
}
/// Writes an IEEE754 double-precision (8 bytes) floating point number to
/// `self` in big-endian byte order.
///
@ -874,6 +1169,33 @@ pub unsafe trait BufMut {
self.put_u64_le(n.to_bits());
}
/// Writes an IEEE754 double-precision (8 bytes) floating point number to
/// `self` in native-endian byte order.
///
/// The current position is advanced by 8.
///
/// # Examples
///
/// ```
/// use bytes::BufMut;
///
/// let mut buf = vec![];
/// buf.put_f64_ne(1.2f64);
/// if cfg!(target_endian = "big") {
/// assert_eq!(buf, b"\x3F\xF3\x33\x33\x33\x33\x33\x33");
/// } else {
/// assert_eq!(buf, b"\x33\x33\x33\x33\x33\x33\xF3\x3F");
/// }
/// ```
///
/// # Panics
///
/// This function panics if there is not enough remaining capacity in
/// `self`.
fn put_f64_ne(&mut self, n: f64) {
self.put_u64_ne(n.to_bits());
}
/// Creates an adaptor which can write at most `limit` bytes to `self`.
///
/// # Examples
@ -986,6 +1308,10 @@ macro_rules! deref_forward_bufmut {
(**self).put_u16_le(n)
}
fn put_u16_ne(&mut self, n: u16) {
(**self).put_u16_ne(n)
}
fn put_i16(&mut self, n: i16) {
(**self).put_i16(n)
}
@ -994,6 +1320,10 @@ macro_rules! deref_forward_bufmut {
(**self).put_i16_le(n)
}
fn put_i16_ne(&mut self, n: i16) {
(**self).put_i16_ne(n)
}
fn put_u32(&mut self, n: u32) {
(**self).put_u32(n)
}
@ -1002,6 +1332,10 @@ macro_rules! deref_forward_bufmut {
(**self).put_u32_le(n)
}
fn put_u32_ne(&mut self, n: u32) {
(**self).put_u32_ne(n)
}
fn put_i32(&mut self, n: i32) {
(**self).put_i32(n)
}
@ -1010,6 +1344,10 @@ macro_rules! deref_forward_bufmut {
(**self).put_i32_le(n)
}
fn put_i32_ne(&mut self, n: i32) {
(**self).put_i32_ne(n)
}
fn put_u64(&mut self, n: u64) {
(**self).put_u64(n)
}
@ -1018,6 +1356,10 @@ macro_rules! deref_forward_bufmut {
(**self).put_u64_le(n)
}
fn put_u64_ne(&mut self, n: u64) {
(**self).put_u64_ne(n)
}
fn put_i64(&mut self, n: i64) {
(**self).put_i64(n)
}
@ -1025,6 +1367,10 @@ macro_rules! deref_forward_bufmut {
fn put_i64_le(&mut self, n: i64) {
(**self).put_i64_le(n)
}
fn put_i64_ne(&mut self, n: i64) {
(**self).put_i64_ne(n)
}
};
}

Просмотреть файл

@ -22,6 +22,10 @@ use core::ops::{
pub struct UninitSlice([MaybeUninit<u8>]);
impl UninitSlice {
pub(crate) fn from_slice(slice: &mut [MaybeUninit<u8>]) -> &mut UninitSlice {
unsafe { &mut *(slice as *mut [MaybeUninit<u8>] as *mut UninitSlice) }
}
/// Create a `&mut UninitSlice` from a pointer and a length.
///
/// # Safety
@ -44,7 +48,7 @@ impl UninitSlice {
pub unsafe fn from_raw_parts_mut<'a>(ptr: *mut u8, len: usize) -> &'a mut UninitSlice {
let maybe_init: &mut [MaybeUninit<u8>] =
core::slice::from_raw_parts_mut(ptr as *mut _, len);
&mut *(maybe_init as *mut [MaybeUninit<u8>] as *mut UninitSlice)
Self::from_slice(maybe_init)
}
/// Write a single byte at the specified offset.

16
third_party/rust/bytes/src/bytes.rs поставляемый
Просмотреть файл

@ -131,7 +131,7 @@ impl Bytes {
/// ```
#[inline]
#[cfg(not(all(loom, test)))]
pub const fn new() -> Bytes {
pub const fn new() -> Self {
// Make it a named const to work around
// "unsizing casts are not allowed in const fn"
const EMPTY: &[u8] = &[];
@ -139,7 +139,7 @@ impl Bytes {
}
#[cfg(all(loom, test))]
pub fn new() -> Bytes {
pub fn new() -> Self {
const EMPTY: &[u8] = &[];
Bytes::from_static(EMPTY)
}
@ -159,7 +159,7 @@ impl Bytes {
/// ```
#[inline]
#[cfg(not(all(loom, test)))]
pub const fn from_static(bytes: &'static [u8]) -> Bytes {
pub const fn from_static(bytes: &'static [u8]) -> Self {
Bytes {
ptr: bytes.as_ptr(),
len: bytes.len(),
@ -169,7 +169,7 @@ impl Bytes {
}
#[cfg(all(loom, test))]
pub fn from_static(bytes: &'static [u8]) -> Bytes {
pub fn from_static(bytes: &'static [u8]) -> Self {
Bytes {
ptr: bytes.as_ptr(),
len: bytes.len(),
@ -235,7 +235,7 @@ impl Bytes {
///
/// Requires that `begin <= end` and `end <= self.len()`, otherwise slicing
/// will panic.
pub fn slice(&self, range: impl RangeBounds<usize>) -> Bytes {
pub fn slice(&self, range: impl RangeBounds<usize>) -> Self {
use core::ops::Bound;
let len = self.len();
@ -302,7 +302,7 @@ impl Bytes {
///
/// Requires that the given `sub` slice is in fact contained within the
/// `Bytes` buffer; otherwise this function will panic.
pub fn slice_ref(&self, subset: &[u8]) -> Bytes {
pub fn slice_ref(&self, subset: &[u8]) -> Self {
// Empty slice and empty Bytes may have their pointers reset
// so explicitly allow empty slice to be a subslice of any slice.
if subset.is_empty() {
@ -359,7 +359,7 @@ impl Bytes {
///
/// Panics if `at > len`.
#[must_use = "consider Bytes::truncate if you don't need the other half"]
pub fn split_off(&mut self, at: usize) -> Bytes {
pub fn split_off(&mut self, at: usize) -> Self {
assert!(
at <= self.len(),
"split_off out of bounds: {:?} <= {:?}",
@ -408,7 +408,7 @@ impl Bytes {
///
/// Panics if `at > len`.
#[must_use = "consider Bytes::advance if you don't need the other half"]
pub fn split_to(&mut self, at: usize) -> Bytes {
pub fn split_to(&mut self, at: usize) -> Self {
assert!(
at <= self.len(),
"split_to out of bounds: {:?} <= {:?}",

52
third_party/rust/bytes/src/bytes_mut.rs поставляемый
Просмотреть файл

@ -1,5 +1,5 @@
use core::iter::{FromIterator, Iterator};
use core::mem::{self, ManuallyDrop};
use core::mem::{self, ManuallyDrop, MaybeUninit};
use core::ops::{Deref, DerefMut};
use core::ptr::{self, NonNull};
use core::{cmp, fmt, hash, isize, slice, usize};
@ -705,6 +705,15 @@ impl BytesMut {
new_cap = cmp::max(double, new_cap);
// No space - allocate more
//
// The length field of `Shared::vec` is not used by the `BytesMut`;
// instead we use the `len` field in the `BytesMut` itself. However,
// when calling `reserve`, it doesn't guarantee that data stored in
// the unused capacity of the vector is copied over to the new
// allocation, so we need to ensure that we don't have any data we
// care about in the unused capacity before calling `reserve`.
debug_assert!(off + len <= v.capacity());
v.set_len(off + len);
v.reserve(new_cap - v.len());
// Update the info
@ -757,11 +766,11 @@ impl BytesMut {
self.reserve(cnt);
unsafe {
let dst = self.uninit_slice();
let dst = self.spare_capacity_mut();
// Reserved above
debug_assert!(dst.len() >= cnt);
ptr::copy_nonoverlapping(extend.as_ptr(), dst.as_mut_ptr(), cnt);
ptr::copy_nonoverlapping(extend.as_ptr(), dst.as_mut_ptr().cast(), cnt);
}
unsafe {
@ -983,13 +992,42 @@ impl BytesMut {
self.data = invalid_ptr((pos << VEC_POS_OFFSET) | (prev & NOT_VEC_POS_MASK));
}
/// Returns the remaining spare capacity of the buffer as a slice of `MaybeUninit<u8>`.
///
/// The returned slice can be used to fill the buffer with data (e.g. by
/// reading from a file) before marking the data as initialized using the
/// [`set_len`] method.
///
/// [`set_len`]: BytesMut::set_len
///
/// # Examples
///
/// ```
/// use bytes::BytesMut;
///
/// // Allocate buffer big enough for 10 bytes.
/// let mut buf = BytesMut::with_capacity(10);
///
/// // Fill in the first 3 elements.
/// let uninit = buf.spare_capacity_mut();
/// uninit[0].write(0);
/// uninit[1].write(1);
/// uninit[2].write(2);
///
/// // Mark the first 3 bytes of the buffer as being initialized.
/// unsafe {
/// buf.set_len(3);
/// }
///
/// assert_eq!(&buf[..], &[0, 1, 2]);
/// ```
#[inline]
fn uninit_slice(&mut self) -> &mut UninitSlice {
pub fn spare_capacity_mut(&mut self) -> &mut [MaybeUninit<u8>] {
unsafe {
let ptr = self.ptr.as_ptr().add(self.len);
let len = self.cap - self.len;
UninitSlice::from_raw_parts_mut(ptr, len)
slice::from_raw_parts_mut(ptr.cast(), len)
}
}
}
@ -1063,7 +1101,7 @@ unsafe impl BufMut for BytesMut {
if self.capacity() == self.len() {
self.reserve(64);
}
self.uninit_slice()
UninitSlice::from_slice(self.spare_capacity_mut())
}
// Specialize these methods so they can skip checking `remaining_mut`
@ -1088,7 +1126,7 @@ unsafe impl BufMut for BytesMut {
fn put_bytes(&mut self, val: u8, cnt: usize) {
self.reserve(cnt);
unsafe {
let dst = self.uninit_slice();
let dst = self.spare_capacity_mut();
// Reserved above
debug_assert!(dst.len() >= cnt);