summaryrefslogtreecommitdiffstats
path: root/third_party/rust/serde_bytes
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
commit2aa4a82499d4becd2284cdb482213d541b8804dd (patch)
treeb80bf8bf13c3766139fbacc530efd0dd9d54394c /third_party/rust/serde_bytes
parentInitial commit. (diff)
downloadfirefox-2aa4a82499d4becd2284cdb482213d541b8804dd.tar.xz
firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.zip
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/serde_bytes')
-rw-r--r--third_party/rust/serde_bytes/.cargo-checksum.json1
-rw-r--r--third_party/rust/serde_bytes/Cargo.toml42
-rw-r--r--third_party/rust/serde_bytes/LICENSE-APACHE201
-rw-r--r--third_party/rust/serde_bytes/LICENSE-MIT25
-rw-r--r--third_party/rust/serde_bytes/README.md54
-rw-r--r--third_party/rust/serde_bytes/src/bytebuf.rs252
-rw-r--r--third_party/rust/serde_bytes/src/bytes.rs195
-rw-r--r--third_party/rust/serde_bytes/src/de.rs105
-rw-r--r--third_party/rust/serde_bytes/src/lib.rs108
-rw-r--r--third_party/rust/serde_bytes/src/ser.rs107
-rw-r--r--third_party/rust/serde_bytes/tests/test_derive.rs36
-rw-r--r--third_party/rust/serde_bytes/tests/test_partialeq.rs13
-rw-r--r--third_party/rust/serde_bytes/tests/test_serde.rs59
13 files changed, 1198 insertions, 0 deletions
diff --git a/third_party/rust/serde_bytes/.cargo-checksum.json b/third_party/rust/serde_bytes/.cargo-checksum.json
new file mode 100644
index 0000000000..83be48fe04
--- /dev/null
+++ b/third_party/rust/serde_bytes/.cargo-checksum.json
@@ -0,0 +1 @@
+{"files":{"Cargo.toml":"1f9bd3cb6643159fef378bf69aadd77ab0b1db6daf8f00cafb3d2a27e9443f31","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"6485b8ed310d3f0340bf1ad1f47645069ce4069dcc6bb46c7d5c6faf41de1fdb","README.md":"ce0f467822b4c8e7427ac10f16a20c26ab2d08a3ac8189a339534f0d116e30c2","src/bytebuf.rs":"a84bc2426fbbcde9d79a1845813fb88590b5b6745d428f6bbf7900954e93b84d","src/bytes.rs":"43ae3033f97e5bd8f8c7ddb2c6e59404e5058a26b1f2d63be0dd988c801a61a2","src/de.rs":"c3041e913c2cb08452adbbec1aa90b040fabc22348fce46a691c527b26832566","src/lib.rs":"baa98727761a560731540232814a4ad180223276b5a2e9767a5c2e808bf6d22a","src/ser.rs":"874eb1cdb82344b263989f3ae1cd06daab6b250d52a1e3abb46b0dccb69fb6ab","tests/test_derive.rs":"fc37391b7b5c81e6ffc7c079c01eb61e8091d49bd6a87c6c3b46d48c94288be6","tests/test_partialeq.rs":"9daa553dfc8a6dc40d88afbfb450d70bad51d90ff7f8df7b707847335b0ffe88","tests/test_serde.rs":"10c980110505d47c7b8a876dcb911154339aa52124b6f1de5636001bcf39b56d"},"package":"45af0182ff64abaeea290235eb67da3825a576c5d53e642c4d5b652e12e6effc"} \ No newline at end of file
diff --git a/third_party/rust/serde_bytes/Cargo.toml b/third_party/rust/serde_bytes/Cargo.toml
new file mode 100644
index 0000000000..ca8207a21b
--- /dev/null
+++ b/third_party/rust/serde_bytes/Cargo.toml
@@ -0,0 +1,42 @@
+# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
+#
+# When uploading crates to the registry Cargo will automatically
+# "normalize" Cargo.toml files for maximal compatibility
+# with all versions of Cargo and also rewrite `path` dependencies
+# to registry (e.g., crates.io) dependencies
+#
+# If you believe there's an error in this file please file an
+# issue against the rust-lang/cargo repository. If you're
+# editing this file be aware that the upstream Cargo.toml
+# will likely look very different (and much more reasonable)
+
+[package]
+edition = "2018"
+name = "serde_bytes"
+version = "0.11.2"
+authors = ["David Tolnay <dtolnay@gmail.com>"]
+description = "Optimized handling of `&[u8]` and `Vec<u8>` for Serde"
+documentation = "https://docs.serde.rs/serde_bytes/"
+readme = "README.md"
+keywords = ["serde", "serialization", "no_std"]
+categories = ["encoding"]
+license = "MIT OR Apache-2.0"
+repository = "https://github.com/serde-rs/bytes"
+[dependencies.serde]
+version = "1.0"
+default-features = false
+[dev-dependencies.bincode]
+version = "1.0"
+
+[dev-dependencies.serde_derive]
+version = "1.0"
+
+[dev-dependencies.serde_test]
+version = "1.0"
+
+[features]
+alloc = ["serde/alloc"]
+default = ["std"]
+std = ["serde/std"]
+[badges.travis-ci]
+repository = "serde-rs/bytes"
diff --git a/third_party/rust/serde_bytes/LICENSE-APACHE b/third_party/rust/serde_bytes/LICENSE-APACHE
new file mode 100644
index 0000000000..16fe87b06e
--- /dev/null
+++ b/third_party/rust/serde_bytes/LICENSE-APACHE
@@ -0,0 +1,201 @@
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+END OF TERMS AND CONDITIONS
+
+APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+Copyright [yyyy] [name of copyright owner]
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
diff --git a/third_party/rust/serde_bytes/LICENSE-MIT b/third_party/rust/serde_bytes/LICENSE-MIT
new file mode 100644
index 0000000000..39d4bdb5ac
--- /dev/null
+++ b/third_party/rust/serde_bytes/LICENSE-MIT
@@ -0,0 +1,25 @@
+Copyright (c) 2014 The Rust Project Developers
+
+Permission is hereby granted, free of charge, to any
+person obtaining a copy of this software and associated
+documentation files (the "Software"), to deal in the
+Software without restriction, including without
+limitation the rights to use, copy, modify, merge,
+publish, distribute, sublicense, and/or sell copies of
+the Software, and to permit persons to whom the Software
+is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice
+shall be included in all copies or substantial portions
+of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
+ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
+TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
+PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
+SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
+IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+DEALINGS IN THE SOFTWARE.
diff --git a/third_party/rust/serde_bytes/README.md b/third_party/rust/serde_bytes/README.md
new file mode 100644
index 0000000000..8546e58525
--- /dev/null
+++ b/third_party/rust/serde_bytes/README.md
@@ -0,0 +1,54 @@
+# serde\_bytes [![Build Status](https://api.travis-ci.org/serde-rs/bytes.svg?branch=master)](https://travis-ci.org/serde-rs/bytes) [![Latest Version](https://img.shields.io/crates/v/serde_bytes.svg)](https://crates.io/crates/serde_bytes)
+
+Wrapper types to enable optimized handling of `&[u8]` and `Vec<u8>`.
+
+```toml
+[dependencies]
+serde_bytes = "0.11"
+```
+
+## Explanation
+
+Without specialization, Rust forces Serde to treat `&[u8]` just like any
+other slice and `Vec<u8>` just like any other vector. In reality this
+particular slice and vector can often be serialized and deserialized in a
+more efficient, compact representation in many formats.
+
+When working with such a format, you can opt into specialized handling of
+`&[u8]` by wrapping it in `serde_bytes::Bytes` and `Vec<u8>` by wrapping it
+in `serde_bytes::ByteBuf`.
+
+Additionally this crate supports the Serde `with` attribute to enable efficient
+handling of `&[u8]` and `Vec<u8>` in structs without needing a wrapper type.
+
+## Example
+
+```rust
+use serde::{Deserialize, Serialize};
+
+#[derive(Deserialize, Serialize)]
+struct Efficient<'a> {
+ #[serde(with = "serde_bytes")]
+ bytes: &'a [u8],
+
+ #[serde(with = "serde_bytes")]
+ byte_buf: Vec<u8>,
+}
+```
+
+<br>
+
+#### License
+
+<sup>
+Licensed under either of <a href="LICENSE-APACHE">Apache License, Version
+2.0</a> or <a href="LICENSE-MIT">MIT license</a> at your option.
+</sup>
+
+<br>
+
+<sub>
+Unless you explicitly state otherwise, any contribution intentionally submitted
+for inclusion in this crate by you, as defined in the Apache-2.0 license, shall
+be dual licensed as above, without any additional terms or conditions.
+</sub>
diff --git a/third_party/rust/serde_bytes/src/bytebuf.rs b/third_party/rust/serde_bytes/src/bytebuf.rs
new file mode 100644
index 0000000000..c3f158aaa3
--- /dev/null
+++ b/third_party/rust/serde_bytes/src/bytebuf.rs
@@ -0,0 +1,252 @@
+use core::borrow::{Borrow, BorrowMut};
+use core::cmp::{self, Ordering};
+use core::fmt::{self, Debug};
+use core::hash::{Hash, Hasher};
+use core::ops::{Deref, DerefMut};
+
+#[cfg(feature = "alloc")]
+use alloc::boxed::Box;
+#[cfg(feature = "alloc")]
+use alloc::string::String;
+#[cfg(feature = "alloc")]
+use alloc::vec::Vec;
+
+use serde::de::{Deserialize, Deserializer, Error, SeqAccess, Visitor};
+use serde::ser::{Serialize, Serializer};
+
+use crate::Bytes;
+
+/// Wrapper around `Vec<u8>` to serialize and deserialize efficiently.
+///
+/// ```
+/// use std::collections::HashMap;
+/// use std::io;
+///
+/// use serde_bytes::ByteBuf;
+///
+/// fn deserialize_bytebufs() -> bincode::Result<()> {
+/// let example_data = [
+/// 2, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 116,
+/// 119, 111, 1, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 111, 110, 101];
+///
+/// let map: HashMap<u32, ByteBuf> = bincode::deserialize(&example_data[..])?;
+///
+/// println!("{:?}", map);
+///
+/// Ok(())
+/// }
+/// #
+/// # fn main() {
+/// # deserialize_bytebufs().unwrap();
+/// # }
+/// ```
+#[derive(Clone, Default, Eq, Ord)]
+pub struct ByteBuf {
+ bytes: Vec<u8>,
+}
+
+impl ByteBuf {
+ /// Construct a new, empty `ByteBuf`.
+ pub fn new() -> Self {
+ ByteBuf::from(Vec::new())
+ }
+
+ /// Construct a new, empty `ByteBuf` with the specified capacity.
+ pub fn with_capacity(cap: usize) -> Self {
+ ByteBuf::from(Vec::with_capacity(cap))
+ }
+
+ /// Wrap existing bytes in a `ByteBuf`.
+ pub fn from<T: Into<Vec<u8>>>(bytes: T) -> Self {
+ ByteBuf {
+ bytes: bytes.into(),
+ }
+ }
+
+ /// Unwrap the vector of byte underlying this `ByteBuf`.
+ pub fn into_vec(self) -> Vec<u8> {
+ self.bytes
+ }
+
+ #[allow(missing_docs)]
+ pub fn into_boxed_bytes(self) -> Box<Bytes> {
+ self.bytes.into_boxed_slice().into()
+ }
+
+ // This would hit "cannot move out of borrowed content" if invoked through
+ // the Deref impl; make it just work.
+ #[doc(hidden)]
+ pub fn into_boxed_slice(self) -> Box<[u8]> {
+ self.bytes.into_boxed_slice()
+ }
+
+ #[doc(hidden)]
+ pub fn into_iter(self) -> <Vec<u8> as IntoIterator>::IntoIter {
+ self.bytes.into_iter()
+ }
+}
+
+impl Debug for ByteBuf {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ Debug::fmt(&self.bytes, f)
+ }
+}
+
+impl AsRef<[u8]> for ByteBuf {
+ fn as_ref(&self) -> &[u8] {
+ &self.bytes
+ }
+}
+
+impl AsMut<[u8]> for ByteBuf {
+ fn as_mut(&mut self) -> &mut [u8] {
+ &mut self.bytes
+ }
+}
+
+impl Deref for ByteBuf {
+ type Target = Vec<u8>;
+
+ fn deref(&self) -> &Self::Target {
+ &self.bytes
+ }
+}
+
+impl DerefMut for ByteBuf {
+ fn deref_mut(&mut self) -> &mut Self::Target {
+ &mut self.bytes
+ }
+}
+
+impl Borrow<Bytes> for ByteBuf {
+ fn borrow(&self) -> &Bytes {
+ Bytes::new(&self.bytes)
+ }
+}
+
+impl BorrowMut<Bytes> for ByteBuf {
+ fn borrow_mut(&mut self) -> &mut Bytes {
+ unsafe { &mut *(&mut self.bytes as &mut [u8] as *mut [u8] as *mut Bytes) }
+ }
+}
+
+impl<Rhs> PartialEq<Rhs> for ByteBuf
+where
+ Rhs: ?Sized + AsRef<[u8]>,
+{
+ fn eq(&self, other: &Rhs) -> bool {
+ self.as_ref().eq(other.as_ref())
+ }
+}
+
+impl<Rhs> PartialOrd<Rhs> for ByteBuf
+where
+ Rhs: ?Sized + AsRef<[u8]>,
+{
+ fn partial_cmp(&self, other: &Rhs) -> Option<Ordering> {
+ self.as_ref().partial_cmp(other.as_ref())
+ }
+}
+
+impl Hash for ByteBuf {
+ fn hash<H: Hasher>(&self, state: &mut H) {
+ self.bytes.hash(state);
+ }
+}
+
+impl IntoIterator for ByteBuf {
+ type Item = u8;
+ type IntoIter = <Vec<u8> as IntoIterator>::IntoIter;
+
+ fn into_iter(self) -> Self::IntoIter {
+ self.bytes.into_iter()
+ }
+}
+
+impl<'a> IntoIterator for &'a ByteBuf {
+ type Item = &'a u8;
+ type IntoIter = <&'a [u8] as IntoIterator>::IntoIter;
+
+ fn into_iter(self) -> Self::IntoIter {
+ self.bytes.iter()
+ }
+}
+
+impl<'a> IntoIterator for &'a mut ByteBuf {
+ type Item = &'a mut u8;
+ type IntoIter = <&'a mut [u8] as IntoIterator>::IntoIter;
+
+ fn into_iter(self) -> Self::IntoIter {
+ self.bytes.iter_mut()
+ }
+}
+
+impl Serialize for ByteBuf {
+ fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
+ where
+ S: Serializer,
+ {
+ serializer.serialize_bytes(&self.bytes)
+ }
+}
+
+struct ByteBufVisitor;
+
+impl<'de> Visitor<'de> for ByteBufVisitor {
+ type Value = ByteBuf;
+
+ fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
+ formatter.write_str("byte array")
+ }
+
+ fn visit_seq<V>(self, mut visitor: V) -> Result<ByteBuf, V::Error>
+ where
+ V: SeqAccess<'de>,
+ {
+ let len = cmp::min(visitor.size_hint().unwrap_or(0), 4096);
+ let mut values = Vec::with_capacity(len);
+
+ while let Some(value) = visitor.next_element()? {
+ values.push(value);
+ }
+
+ Ok(ByteBuf::from(values))
+ }
+
+ fn visit_bytes<E>(self, v: &[u8]) -> Result<ByteBuf, E>
+ where
+ E: Error,
+ {
+ Ok(ByteBuf::from(v))
+ }
+
+ fn visit_byte_buf<E>(self, v: Vec<u8>) -> Result<ByteBuf, E>
+ where
+ E: Error,
+ {
+ Ok(ByteBuf::from(v))
+ }
+
+ fn visit_str<E>(self, v: &str) -> Result<ByteBuf, E>
+ where
+ E: Error,
+ {
+ Ok(ByteBuf::from(v))
+ }
+
+ fn visit_string<E>(self, v: String) -> Result<ByteBuf, E>
+ where
+ E: Error,
+ {
+ Ok(ByteBuf::from(v))
+ }
+}
+
+impl<'de> Deserialize<'de> for ByteBuf {
+ fn deserialize<D>(deserializer: D) -> Result<ByteBuf, D::Error>
+ where
+ D: Deserializer<'de>,
+ {
+ deserializer.deserialize_byte_buf(ByteBufVisitor)
+ }
+}
diff --git a/third_party/rust/serde_bytes/src/bytes.rs b/third_party/rust/serde_bytes/src/bytes.rs
new file mode 100644
index 0000000000..8fafbf5d9d
--- /dev/null
+++ b/third_party/rust/serde_bytes/src/bytes.rs
@@ -0,0 +1,195 @@
+use core::cmp::Ordering;
+use core::fmt::{self, Debug};
+use core::hash::{Hash, Hasher};
+use core::ops::{Deref, DerefMut};
+
+#[cfg(feature = "alloc")]
+use alloc::borrow::ToOwned;
+
+#[cfg(feature = "alloc")]
+use alloc::boxed::Box;
+
+#[cfg(any(feature = "std", feature = "alloc"))]
+use crate::ByteBuf;
+
+use serde::de::{Deserialize, Deserializer, Error, Visitor};
+use serde::ser::{Serialize, Serializer};
+
+/// Wrapper around `&[u8]` to serialize and deserialize efficiently.
+///
+/// ```
+/// use std::collections::HashMap;
+/// use std::io;
+///
+/// use serde_bytes::Bytes;
+///
+/// fn print_encoded_cache() -> bincode::Result<()> {
+/// let mut cache = HashMap::new();
+/// cache.insert(3, Bytes::new(b"three"));
+/// cache.insert(2, Bytes::new(b"two"));
+/// cache.insert(1, Bytes::new(b"one"));
+///
+/// bincode::serialize_into(&mut io::stdout(), &cache)
+/// }
+/// #
+/// # fn main() {
+/// # print_encoded_cache().unwrap();
+/// # }
+/// ```
+#[derive(Eq, Ord)]
+#[repr(C)]
+pub struct Bytes {
+ bytes: [u8],
+}
+
+impl Bytes {
+ /// Wrap an existing `&[u8]`.
+ pub fn new(bytes: &[u8]) -> &Self {
+ unsafe { &*(bytes as *const [u8] as *const Bytes) }
+ }
+}
+
+impl Debug for Bytes {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ Debug::fmt(&self.bytes, f)
+ }
+}
+
+impl AsRef<[u8]> for Bytes {
+ fn as_ref(&self) -> &[u8] {
+ &self.bytes
+ }
+}
+
+impl AsMut<[u8]> for Bytes {
+ fn as_mut(&mut self) -> &mut [u8] {
+ &mut self.bytes
+ }
+}
+
+impl Deref for Bytes {
+ type Target = [u8];
+
+ fn deref(&self) -> &Self::Target {
+ &self.bytes
+ }
+}
+
+impl DerefMut for Bytes {
+ fn deref_mut(&mut self) -> &mut Self::Target {
+ &mut self.bytes
+ }
+}
+
+#[cfg(any(feature = "std", feature = "alloc"))]
+impl ToOwned for Bytes {
+ type Owned = ByteBuf;
+
+ fn to_owned(&self) -> Self::Owned {
+ ByteBuf::from(&self.bytes)
+ }
+}
+
+#[cfg(any(feature = "std", feature = "alloc"))]
+impl From<Box<[u8]>> for Box<Bytes> {
+ fn from(bytes: Box<[u8]>) -> Self {
+ unsafe { Box::from_raw(Box::into_raw(bytes) as *mut Bytes) }
+ }
+}
+
+impl<'a> Default for &'a Bytes {
+ fn default() -> Self {
+ Bytes::new(&[])
+ }
+}
+
+#[cfg(any(feature = "std", feature = "alloc"))]
+impl Default for Box<Bytes> {
+ fn default() -> Self {
+ ByteBuf::new().into_boxed_bytes()
+ }
+}
+
+impl<Rhs> PartialEq<Rhs> for Bytes
+where
+ Rhs: ?Sized + AsRef<[u8]>,
+{
+ fn eq(&self, other: &Rhs) -> bool {
+ self.as_ref().eq(other.as_ref())
+ }
+}
+
+impl<Rhs> PartialOrd<Rhs> for Bytes
+where
+ Rhs: ?Sized + AsRef<[u8]>,
+{
+ fn partial_cmp(&self, other: &Rhs) -> Option<Ordering> {
+ self.as_ref().partial_cmp(other.as_ref())
+ }
+}
+
+impl Hash for Bytes {
+ fn hash<H: Hasher>(&self, state: &mut H) {
+ self.bytes.hash(state);
+ }
+}
+
+impl<'a> IntoIterator for &'a Bytes {
+ type Item = &'a u8;
+ type IntoIter = <&'a [u8] as IntoIterator>::IntoIter;
+
+ fn into_iter(self) -> Self::IntoIter {
+ self.bytes.iter()
+ }
+}
+
+impl<'a> IntoIterator for &'a mut Bytes {
+ type Item = &'a mut u8;
+ type IntoIter = <&'a mut [u8] as IntoIterator>::IntoIter;
+
+ fn into_iter(self) -> Self::IntoIter {
+ self.bytes.iter_mut()
+ }
+}
+
+impl Serialize for Bytes {
+ fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
+ where
+ S: Serializer,
+ {
+ serializer.serialize_bytes(&self.bytes)
+ }
+}
+
+struct BytesVisitor;
+
+impl<'de> Visitor<'de> for BytesVisitor {
+ type Value = &'de Bytes;
+
+ fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
+ formatter.write_str("a borrowed byte array")
+ }
+
+ fn visit_borrowed_bytes<E>(self, v: &'de [u8]) -> Result<Self::Value, E>
+ where
+ E: Error,
+ {
+ Ok(Bytes::new(v))
+ }
+
+ fn visit_borrowed_str<E>(self, v: &'de str) -> Result<Self::Value, E>
+ where
+ E: Error,
+ {
+ Ok(Bytes::new(v.as_bytes()))
+ }
+}
+
+impl<'a, 'de: 'a> Deserialize<'de> for &'a Bytes {
+ fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
+ where
+ D: Deserializer<'de>,
+ {
+ deserializer.deserialize_bytes(BytesVisitor)
+ }
+}
diff --git a/third_party/rust/serde_bytes/src/de.rs b/third_party/rust/serde_bytes/src/de.rs
new file mode 100644
index 0000000000..862368aaee
--- /dev/null
+++ b/third_party/rust/serde_bytes/src/de.rs
@@ -0,0 +1,105 @@
+use crate::Bytes;
+use serde::Deserializer;
+
+#[cfg(any(feature = "std", feature = "alloc"))]
+use crate::ByteBuf;
+
+#[cfg(feature = "alloc")]
+use alloc::borrow::Cow;
+#[cfg(all(feature = "std", not(feature = "alloc")))]
+use std::borrow::Cow;
+
+#[cfg(feature = "alloc")]
+use alloc::boxed::Box;
+
+#[cfg(feature = "alloc")]
+use alloc::vec::Vec;
+
+/// Types that can be deserialized via `#[serde(with = "serde_bytes")]`.
+pub trait Deserialize<'de>: Sized {
+ #[allow(missing_docs)]
+ fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
+ where
+ D: Deserializer<'de>;
+}
+
+impl<'de: 'a, 'a> Deserialize<'de> for &'a [u8] {
+ fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
+ where
+ D: Deserializer<'de>,
+ {
+ // Via the serde::Deserialize impl for &[u8].
+ serde::Deserialize::deserialize(deserializer)
+ }
+}
+
+#[cfg(any(feature = "std", feature = "alloc"))]
+impl<'de> Deserialize<'de> for Vec<u8> {
+ fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
+ where
+ D: Deserializer<'de>,
+ {
+ Deserialize::deserialize(deserializer).map(ByteBuf::into_vec)
+ }
+}
+
+impl<'de: 'a, 'a> Deserialize<'de> for &'a Bytes {
+ fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
+ where
+ D: Deserializer<'de>,
+ {
+ Deserialize::deserialize(deserializer).map(Bytes::new)
+ }
+}
+
+#[cfg(any(feature = "std", feature = "alloc"))]
+impl<'de> Deserialize<'de> for ByteBuf {
+ fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
+ where
+ D: Deserializer<'de>,
+ {
+ // Via the serde::Deserialize impl for ByteBuf.
+ serde::Deserialize::deserialize(deserializer)
+ }
+}
+
+#[cfg(any(feature = "std", feature = "alloc"))]
+impl<'de: 'a, 'a> Deserialize<'de> for Cow<'a, [u8]> {
+ fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
+ where
+ D: Deserializer<'de>,
+ {
+ Deserialize::deserialize(deserializer).map(Cow::Borrowed)
+ }
+}
+
+#[cfg(any(feature = "std", feature = "alloc"))]
+impl<'de: 'a, 'a> Deserialize<'de> for Cow<'a, Bytes> {
+ fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
+ where
+ D: Deserializer<'de>,
+ {
+ Deserialize::deserialize(deserializer).map(Cow::Borrowed)
+ }
+}
+
+#[cfg(any(feature = "std", feature = "alloc"))]
+impl<'de> Deserialize<'de> for Box<[u8]> {
+ fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
+ where
+ D: Deserializer<'de>,
+ {
+ Deserialize::deserialize(deserializer).map(Vec::into_boxed_slice)
+ }
+}
+
+#[cfg(any(feature = "std", feature = "alloc"))]
+impl<'de> Deserialize<'de> for Box<Bytes> {
+ fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
+ where
+ D: Deserializer<'de>,
+ {
+ let bytes: Box<[u8]> = Deserialize::deserialize(deserializer)?;
+ Ok(bytes.into())
+ }
+}
diff --git a/third_party/rust/serde_bytes/src/lib.rs b/third_party/rust/serde_bytes/src/lib.rs
new file mode 100644
index 0000000000..9912623c2f
--- /dev/null
+++ b/third_party/rust/serde_bytes/src/lib.rs
@@ -0,0 +1,108 @@
+//! Wrapper types to enable optimized handling of `&[u8]` and `Vec<u8>`.
+//!
+//! Without specialization, Rust forces Serde to treat `&[u8]` just like any
+//! other slice and `Vec<u8>` just like any other vector. In reality this
+//! particular slice and vector can often be serialized and deserialized in a
+//! more efficient, compact representation in many formats.
+//!
+//! When working with such a format, you can opt into specialized handling of
+//! `&[u8]` by wrapping it in `serde_bytes::Bytes` and `Vec<u8>` by wrapping it
+//! in `serde_bytes::ByteBuf`.
+//!
+//! Additionally this crate supports the Serde `with` attribute to enable
+//! efficient handling of `&[u8]` and `Vec<u8>` in structs without needing a
+//! wrapper type.
+//!
+//! ```
+//! # use serde_derive::{Deserialize, Serialize};
+//! use serde::{Deserialize, Serialize};
+//!
+//! #[derive(Deserialize, Serialize)]
+//! struct Efficient<'a> {
+//! #[serde(with = "serde_bytes")]
+//! bytes: &'a [u8],
+//!
+//! #[serde(with = "serde_bytes")]
+//! byte_buf: Vec<u8>,
+//! }
+//! ```
+
+#![doc(html_root_url = "https://docs.rs/serde_bytes/0.11.2")]
+#![cfg_attr(not(feature = "std"), no_std)]
+#![deny(missing_docs)]
+
+mod bytes;
+mod de;
+mod ser;
+
+#[cfg(any(feature = "std", feature = "alloc"))]
+mod bytebuf;
+
+#[cfg(feature = "alloc")]
+extern crate alloc;
+
+#[cfg(any(feature = "std", feature = "alloc"))]
+use serde::Deserializer;
+
+use serde::Serializer;
+
+pub use crate::bytes::Bytes;
+pub use crate::de::Deserialize;
+pub use crate::ser::Serialize;
+
+#[cfg(any(feature = "std", feature = "alloc"))]
+pub use crate::bytebuf::ByteBuf;
+
+/// Serde `serialize_with` function to serialize bytes efficiently.
+///
+/// This function can be used with either of the following Serde attributes:
+///
+/// - `#[serde(with = "serde_bytes")]`
+/// - `#[serde(serialize_with = "serde_bytes::serialize")]`
+///
+/// ```
+/// # use serde_derive::Serialize;
+/// use serde::Serialize;
+///
+/// #[derive(Serialize)]
+/// struct Efficient<'a> {
+/// #[serde(with = "serde_bytes")]
+/// bytes: &'a [u8],
+///
+/// #[serde(with = "serde_bytes")]
+/// byte_buf: Vec<u8>,
+/// }
+/// ```
+pub fn serialize<T, S>(bytes: &T, serializer: S) -> Result<S::Ok, S::Error>
+where
+ T: ?Sized + Serialize,
+ S: Serializer,
+{
+ Serialize::serialize(bytes, serializer)
+}
+
+/// Serde `deserialize_with` function to deserialize bytes efficiently.
+///
+/// This function can be used with either of the following Serde attributes:
+///
+/// - `#[serde(with = "serde_bytes")]`
+/// - `#[serde(deserialize_with = "serde_bytes::deserialize")]`
+///
+/// ```
+/// # use serde_derive::Deserialize;
+/// use serde::Deserialize;
+///
+/// #[derive(Deserialize)]
+/// struct Packet {
+/// #[serde(with = "serde_bytes")]
+/// payload: Vec<u8>,
+/// }
+/// ```
+#[cfg(any(feature = "std", feature = "alloc"))]
+pub fn deserialize<'de, T, D>(deserializer: D) -> Result<T, D::Error>
+where
+ T: Deserialize<'de>,
+ D: Deserializer<'de>,
+{
+ Deserialize::deserialize(deserializer)
+}
diff --git a/third_party/rust/serde_bytes/src/ser.rs b/third_party/rust/serde_bytes/src/ser.rs
new file mode 100644
index 0000000000..808ef96760
--- /dev/null
+++ b/third_party/rust/serde_bytes/src/ser.rs
@@ -0,0 +1,107 @@
+use crate::Bytes;
+use serde::Serializer;
+
+#[cfg(any(feature = "std", feature = "alloc"))]
+use crate::ByteBuf;
+
+#[cfg(feature = "alloc")]
+use alloc::borrow::Cow;
+#[cfg(all(feature = "std", not(feature = "alloc")))]
+use std::borrow::Cow;
+
+#[cfg(feature = "alloc")]
+use alloc::boxed::Box;
+
+#[cfg(feature = "alloc")]
+use alloc::vec::Vec;
+
+/// Types that can be serialized via `#[serde(with = "serde_bytes")]`.
+pub trait Serialize {
+ #[allow(missing_docs)]
+ fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
+ where
+ S: Serializer;
+}
+
+impl Serialize for [u8] {
+ fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
+ where
+ S: Serializer,
+ {
+ serializer.serialize_bytes(self)
+ }
+}
+
+#[cfg(any(feature = "std", feature = "alloc"))]
+impl Serialize for Vec<u8> {
+ fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
+ where
+ S: Serializer,
+ {
+ serializer.serialize_bytes(self)
+ }
+}
+
+impl Serialize for Bytes {
+ fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
+ where
+ S: Serializer,
+ {
+ serializer.serialize_bytes(self)
+ }
+}
+
+#[cfg(any(feature = "std", feature = "alloc"))]
+impl Serialize for ByteBuf {
+ fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
+ where
+ S: Serializer,
+ {
+ serializer.serialize_bytes(self)
+ }
+}
+
+#[cfg(any(feature = "std", feature = "alloc"))]
+impl<'a> Serialize for Cow<'a, [u8]> {
+ fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
+ where
+ S: Serializer,
+ {
+ serializer.serialize_bytes(self)
+ }
+}
+
+#[cfg(any(feature = "std", feature = "alloc"))]
+impl<'a> Serialize for Cow<'a, Bytes> {
+ fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
+ where
+ S: Serializer,
+ {
+ serializer.serialize_bytes(self)
+ }
+}
+
+impl<'a, T> Serialize for &'a T
+where
+ T: ?Sized + Serialize,
+{
+ fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
+ where
+ S: Serializer,
+ {
+ (**self).serialize(serializer)
+ }
+}
+
+#[cfg(any(feature = "std", feature = "alloc"))]
+impl<T> Serialize for Box<T>
+where
+ T: ?Sized + Serialize,
+{
+ fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
+ where
+ S: Serializer,
+ {
+ (**self).serialize(serializer)
+ }
+}
diff --git a/third_party/rust/serde_bytes/tests/test_derive.rs b/third_party/rust/serde_bytes/tests/test_derive.rs
new file mode 100644
index 0000000000..af0bbd89de
--- /dev/null
+++ b/third_party/rust/serde_bytes/tests/test_derive.rs
@@ -0,0 +1,36 @@
+use serde_bytes::{ByteBuf, Bytes};
+use serde_derive::{Deserialize, Serialize};
+use std::borrow::Cow;
+
+#[derive(Serialize, Deserialize, PartialEq, Debug)]
+struct Test<'a> {
+ #[serde(with = "serde_bytes")]
+ slice: &'a [u8],
+
+ #[serde(with = "serde_bytes")]
+ vec: Vec<u8>,
+
+ #[serde(with = "serde_bytes")]
+ bytes: &'a Bytes,
+
+ #[serde(with = "serde_bytes")]
+ byte_buf: ByteBuf,
+
+ #[serde(with = "serde_bytes")]
+ cow_slice: Cow<'a, [u8]>,
+
+ #[serde(with = "serde_bytes")]
+ cow_bytes: Cow<'a, Bytes>,
+
+ #[serde(with = "serde_bytes")]
+ boxed_slice: Box<[u8]>,
+
+ #[serde(with = "serde_bytes")]
+ boxed_bytes: Box<Bytes>,
+}
+
+#[derive(Serialize)]
+struct Dst {
+ #[serde(with = "serde_bytes")]
+ bytes: [u8],
+}
diff --git a/third_party/rust/serde_bytes/tests/test_partialeq.rs b/third_party/rust/serde_bytes/tests/test_partialeq.rs
new file mode 100644
index 0000000000..549764135e
--- /dev/null
+++ b/third_party/rust/serde_bytes/tests/test_partialeq.rs
@@ -0,0 +1,13 @@
+use serde_bytes::{Bytes, ByteBuf};
+
+fn _bytes_eq_slice(bytes: &Bytes, slice: &[u8]) -> bool {
+ bytes == slice
+}
+
+fn _bytebuf_eq_vec(bytebuf: ByteBuf, vec: Vec<u8>) -> bool {
+ bytebuf == vec
+}
+
+fn _bytes_eq_bytestring(bytes: &Bytes) -> bool {
+ bytes == b"..."
+}
diff --git a/third_party/rust/serde_bytes/tests/test_serde.rs b/third_party/rust/serde_bytes/tests/test_serde.rs
new file mode 100644
index 0000000000..d48e3fd434
--- /dev/null
+++ b/third_party/rust/serde_bytes/tests/test_serde.rs
@@ -0,0 +1,59 @@
+use serde_bytes::{ByteBuf, Bytes};
+use serde_test::{assert_de_tokens, assert_ser_tokens, assert_tokens, Token};
+
+#[test]
+fn test_bytes() {
+ let empty = Bytes::new(&[]);
+ assert_tokens(&empty, &[Token::BorrowedBytes(b"")]);
+ assert_ser_tokens(&empty, &[Token::Bytes(b"")]);
+ assert_ser_tokens(&empty, &[Token::ByteBuf(b"")]);
+ assert_de_tokens(&empty, &[Token::BorrowedStr("")]);
+
+ let buf = vec![65, 66, 67];
+ let bytes = Bytes::new(&buf);
+ assert_tokens(&bytes, &[Token::BorrowedBytes(b"ABC")]);
+ assert_ser_tokens(&bytes, &[Token::Bytes(b"ABC")]);
+ assert_ser_tokens(&bytes, &[Token::ByteBuf(b"ABC")]);
+ assert_de_tokens(&bytes, &[Token::BorrowedStr("ABC")]);
+}
+
+#[test]
+fn test_byte_buf() {
+ let empty = ByteBuf::new();
+ assert_tokens(&empty, &[Token::BorrowedBytes(b"")]);
+ assert_tokens(&empty, &[Token::Bytes(b"")]);
+ assert_tokens(&empty, &[Token::ByteBuf(b"")]);
+ assert_de_tokens(&empty, &[Token::BorrowedStr("")]);
+ assert_de_tokens(&empty, &[Token::Str("")]);
+ assert_de_tokens(&empty, &[Token::String("")]);
+ assert_de_tokens(&empty, &[Token::Seq { len: None }, Token::SeqEnd]);
+ assert_de_tokens(&empty, &[Token::Seq { len: Some(0) }, Token::SeqEnd]);
+
+ let buf = ByteBuf::from(vec![65, 66, 67]);
+ assert_tokens(&buf, &[Token::BorrowedBytes(b"ABC")]);
+ assert_tokens(&buf, &[Token::Bytes(b"ABC")]);
+ assert_tokens(&buf, &[Token::ByteBuf(b"ABC")]);
+ assert_de_tokens(&buf, &[Token::BorrowedStr("ABC")]);
+ assert_de_tokens(&buf, &[Token::Str("ABC")]);
+ assert_de_tokens(&buf, &[Token::String("ABC")]);
+ assert_de_tokens(
+ &buf,
+ &[
+ Token::Seq { len: None },
+ Token::U8(65),
+ Token::U8(66),
+ Token::U8(67),
+ Token::SeqEnd,
+ ],
+ );
+ assert_de_tokens(
+ &buf,
+ &[
+ Token::Seq { len: Some(3) },
+ Token::U8(65),
+ Token::U8(66),
+ Token::U8(67),
+ Token::SeqEnd,
+ ],
+ );
+}