From b7a889c98b2b4e3eb294643643ed3604dd2006aa Mon Sep 17 00:00:00 2001 From: Kartikaya Gupta Date: Wed, 4 Apr 2018 15:23:28 -0400 Subject: [PATCH] Bug 1449562 - Update Cargo lockfiles and re-vendor rust dependencies. r=jrmuizel MozReview-Commit-ID: LhqEX4QClN9 --HG-- extra : rebase_source : 77790431f7ced5bfa332a7b1694754e9fe96a275 --- Cargo.lock | 25 +- .../rust/freetype/.cargo-checksum.json | 2 +- third_party/rust/freetype/Cargo.toml | 8 +- third_party/rust/freetype/src/lib.rs | 13 +- .../rust/serde_bytes/.cargo-checksum.json | 1 + third_party/rust/serde_bytes/Cargo.toml | 41 ++ third_party/rust/serde_bytes/LICENSE-APACHE | 201 ++++++++ third_party/rust/serde_bytes/LICENSE-MIT | 25 + third_party/rust/serde_bytes/README.md | 55 +++ third_party/rust/serde_bytes/src/lib.rs | 431 ++++++++++++++++++ third_party/rust/serde_bytes/src/value.rs | 91 ++++ 11 files changed, 872 insertions(+), 21 deletions(-) create mode 100644 third_party/rust/serde_bytes/.cargo-checksum.json create mode 100644 third_party/rust/serde_bytes/Cargo.toml create mode 100644 third_party/rust/serde_bytes/LICENSE-APACHE create mode 100644 third_party/rust/serde_bytes/LICENSE-MIT create mode 100644 third_party/rust/serde_bytes/README.md create mode 100644 third_party/rust/serde_bytes/src/lib.rs create mode 100644 third_party/rust/serde_bytes/src/value.rs diff --git a/Cargo.lock b/Cargo.lock index 8c053058a762..0c0d653e0db3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -607,7 +607,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "freetype" -version = "0.3.0" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "libc 0.2.39 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1580,6 +1580,14 @@ dependencies = [ "serde_derive 1.0.35 (git+https://github.com/servo/serde?branch=deserialize_from_enums5)", ] +[[package]] +name = "serde_bytes" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "serde 1.0.35 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "serde_derive" version = "1.0.35" @@ -2050,18 +2058,19 @@ dependencies = [ [[package]] name = "webrender" -version = "0.57.0" +version = "0.57.2" dependencies = [ "app_units 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "bincode 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "bitflags 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "byteorder 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "core-foundation 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "core-graphics 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)", "core-text 9.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "dwrote 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.17.2 (registry+https://github.com/rust-lang/crates.io-index)", - "freetype 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "freetype 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "fxhash 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "gleam 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2074,12 +2083,12 @@ dependencies = [ "smallvec 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "thread_profiler 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.38 (registry+https://github.com/rust-lang/crates.io-index)", - "webrender_api 0.57.0", + "webrender_api 0.57.2", ] [[package]] name = "webrender_api" -version = "0.57.0" +version = "0.57.2" dependencies = [ "app_units 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "bincode 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2090,6 +2099,7 @@ dependencies = [ "dwrote 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.17.2 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.35 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_bytes 0.10.4 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.35 (git+https://github.com/servo/serde?branch=deserialize_from_enums5)", "time 0.1.38 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2108,7 +2118,7 @@ dependencies = [ "log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "rayon 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "thread_profiler 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "webrender 0.57.0", + "webrender 0.57.2", ] [[package]] @@ -2285,7 +2295,7 @@ dependencies = [ "checksum flate2 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9fac2277e84e5e858483756647a9d0aa8d9a2b7cba517fd84325a0aaa69a0909" "checksum fnv 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "6cc484842f1e2884faf56f529f960cc12ad8c71ce96cc7abba0a067c98fee344" "checksum foreign-types 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5ebc04f19019fff1f2d627b5581574ead502f80c48c88900575a46e0840fe5d0" -"checksum freetype 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "398b8a11884898184d55aca9806f002b3cf68f0e860e0cbb4586f834ee39b0e7" +"checksum freetype 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b659e75b7a7338fe75afd7f909fc2b71937845cffb6ebe54ba2e50f13d8e903d" "checksum fs2 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9ab76cfd2aaa59b7bf6688ad9ba15bbae64bff97f04ea02144cfd3443e5c2866" "checksum fuchsia-zircon 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f6c0581a4e363262e52b87f59ee2afe3415361c6ec35e665924eb08afe8ff159" "checksum fuchsia-zircon-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "43f3795b4bae048dc6123a6b972cadde2e676f9ded08aef6bb77f5f157684a82" @@ -2375,6 +2385,7 @@ dependencies = [ "checksum semver 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7a3186ec9e65071a2095434b1f5bb24838d4e8e130f584c790f6033c79943537" "checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" "checksum serde 1.0.35 (registry+https://github.com/rust-lang/crates.io-index)" = "800fdb0a894572994f3970035a8a5f65d8ec2cd40e6cdf7d8cd9001d7b30648e" +"checksum serde_bytes 0.10.4 (registry+https://github.com/rust-lang/crates.io-index)" = "adb6e51a6b3696b301bc221d785f898b4457c619b51d7ce195a6d20baecb37b3" "checksum serde_derive 1.0.35 (git+https://github.com/servo/serde?branch=deserialize_from_enums5)" = "" "checksum serde_derive_internals 0.22.1 (git+https://github.com/servo/serde?branch=deserialize_from_enums5)" = "" "checksum simd 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3dd0805c7363ab51a829a1511ad24b6ed0349feaa756c4bc2f977f9f496e6673" diff --git a/third_party/rust/freetype/.cargo-checksum.json b/third_party/rust/freetype/.cargo-checksum.json index c5d2fc41c0d8..d1142c4fdd3e 100644 --- a/third_party/rust/freetype/.cargo-checksum.json +++ b/third_party/rust/freetype/.cargo-checksum.json @@ -1 +1 @@ -{"files":{".travis.yml":"b66e958a27e280a79ae1742be91e02cbaf7392851d430f19b13f3619861860e2","COPYRIGHT":"ec82b96487e9e778ee610c7ab245162464782cfa1f555c2299333f8dbe5c036a","Cargo.toml":"ec1a0a3ceb37de795193e244fb3781cf87d25ea610f150976958468881da76a7","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"62065228e42caebca7e7d7db1204cbb867033de5982ca4009928915e4095f3a3","Makefile.in":"7348b5f8a577048279b3f98e2c2b5705f506cf5b4b1e6bb542cc0b1e62468411","README.md":"755e885eb12f7b0b459c8b579f20cd941e55f0197b947591131daf048c5d7bc6","configure":"e0e6ba778e5f5784fa87abf235aa4f3da750d922bfb26a34803d9674577d56ec","etc/bindgen.sh":"39c1d5298f6e46380f0616d6080bd2c3ead5f04149bcf5b7345c56dae2000e79","etc/bindings.h":"b531980f5739536dfc1484236d436efd18f448b4ea15001d1dfbbaf381ad054f","src/freetype.rs":"445a3d48974dcf22961b612ef6cdef48c2dedc1ccc6e73a88eee53fa601859d8","src/lib.rs":"812e79af46e33a93420c8301ad95392f5e8a57266b3e43c47085c6dd0c63653f","src/tt_os2.rs":"9517c53fc4e575ceb615d554dc72812dcbb532bf94883d51202b24caae1a1418"},"package":"398b8a11884898184d55aca9806f002b3cf68f0e860e0cbb4586f834ee39b0e7"} \ No newline at end of file +{"files":{".travis.yml":"b66e958a27e280a79ae1742be91e02cbaf7392851d430f19b13f3619861860e2","COPYRIGHT":"ec82b96487e9e778ee610c7ab245162464782cfa1f555c2299333f8dbe5c036a","Cargo.toml":"9d0d120e9d1823f3adab634f7e2762fda8cf328666d11378010d650fd334e1e8","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"62065228e42caebca7e7d7db1204cbb867033de5982ca4009928915e4095f3a3","Makefile.in":"7348b5f8a577048279b3f98e2c2b5705f506cf5b4b1e6bb542cc0b1e62468411","README.md":"755e885eb12f7b0b459c8b579f20cd941e55f0197b947591131daf048c5d7bc6","configure":"e0e6ba778e5f5784fa87abf235aa4f3da750d922bfb26a34803d9674577d56ec","etc/bindgen.sh":"39c1d5298f6e46380f0616d6080bd2c3ead5f04149bcf5b7345c56dae2000e79","etc/bindings.h":"b531980f5739536dfc1484236d436efd18f448b4ea15001d1dfbbaf381ad054f","src/freetype.rs":"445a3d48974dcf22961b612ef6cdef48c2dedc1ccc6e73a88eee53fa601859d8","src/lib.rs":"cbd3e98926f89fceffd535ea5588a1ee1fa7c7052625a579e28271c266908367","src/tt_os2.rs":"9517c53fc4e575ceb615d554dc72812dcbb532bf94883d51202b24caae1a1418"},"package":"b659e75b7a7338fe75afd7f909fc2b71937845cffb6ebe54ba2e50f13d8e903d"} \ No newline at end of file diff --git a/third_party/rust/freetype/Cargo.toml b/third_party/rust/freetype/Cargo.toml index 23a7384f4dba..54af8dbcc4e2 100644 --- a/third_party/rust/freetype/Cargo.toml +++ b/third_party/rust/freetype/Cargo.toml @@ -12,7 +12,7 @@ [package] name = "freetype" -version = "0.3.0" +version = "0.4.0" authors = ["The Servo Project Developers"] description = "Bindings for Freetype used by Servo" documentation = "http://doc.servo.org/freetype/" @@ -22,12 +22,12 @@ repository = "https://github.com/servo/rust-freetype" [lib] name = "freetype" crate-type = ["rlib"] +[dependencies.libc] +version = "0.2" + [dependencies.servo-freetype-sys] version = "4.0.2" optional = true -[dependencies.libc] -version = "0.2" - [features] default = ["servo-freetype-sys"] diff --git a/third_party/rust/freetype/src/lib.rs b/third_party/rust/freetype/src/lib.rs index 7831e2ecffec..e2356a90f269 100644 --- a/third_party/rust/freetype/src/lib.rs +++ b/third_party/rust/freetype/src/lib.rs @@ -20,16 +20,11 @@ extern crate freetype_sys; extern crate libc; -/// A wrapper over FT_Error so we can add convenience methods on it. -#[repr(C)] -#[derive(Copy, Clone, PartialEq, Eq, Debug)] -pub struct FT_Error(pub ::std::os::raw::c_int); +pub type FT_Error = ::std::os::raw::c_int; -impl FT_Error { - #[inline] - pub fn succeeded(&self) -> bool { - self.0 == freetype::FT_Err_Ok as ::std::os::raw::c_int - } +#[inline] +pub fn succeeded(error: FT_Error) -> bool { + error == freetype::FT_Err_Ok as FT_Error } #[allow(improper_ctypes)] // https://github.com/rust-lang/rust/issues/34798 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 000000000000..a929bc153770 --- /dev/null +++ b/third_party/rust/serde_bytes/.cargo-checksum.json @@ -0,0 +1 @@ +{"files":{"Cargo.toml":"acd21fe58d1af762230c1dec07b9e0131d65b1751f5e5d0aebb7cd6f79f56720","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"6485b8ed310d3f0340bf1ad1f47645069ce4069dcc6bb46c7d5c6faf41de1fdb","README.md":"f0b7988c93ab594ca02b313b312b97a4c83669cd31aa0705711c113052130144","src/lib.rs":"cc5ff1cc84363022ac02e7291976b8d8d679cf5fbd021f192570c59e4011ddbd","src/value.rs":"911090aa5f4b0ee7ea00a8fe9d72e4df33dd4d9017689f0bdf97fa3a3d267817"},"package":"adb6e51a6b3696b301bc221d785f898b4457c619b51d7ce195a6d20baecb37b3"} \ 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 000000000000..ddef170b565f --- /dev/null +++ b/third_party/rust/serde_bytes/Cargo.toml @@ -0,0 +1,41 @@ +# 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] +name = "serde_bytes" +version = "0.10.4" +authors = ["David Tolnay "] +include = ["Cargo.toml", "src/**/*.rs", "README.md", "LICENSE-APACHE", "LICENSE-MIT"] +description = "Optimized handling of `&[u8]` and `Vec` for Serde" +homepage = "https://serde.rs" +documentation = "https://docs.serde.rs/serde_bytes/" +readme = "README.md" +keywords = ["serde", "serialization", "no_std"] +categories = ["encoding"] +license = "MIT/Apache-2.0" +repository = "https://github.com/serde-rs/bytes" +[dependencies.serde] +version = "1.0" +default-features = false +[dev-dependencies.bincode] +version = "0.8" + +[dev-dependencies.serde_derive] +version = "1.0" + +[dev-dependencies.serde_test] +version = "1.0" + +[features] +alloc = ["serde/alloc"] +default = ["std"] +std = ["serde/std"] diff --git a/third_party/rust/serde_bytes/LICENSE-APACHE b/third_party/rust/serde_bytes/LICENSE-APACHE new file mode 100644 index 000000000000..16fe87b06e80 --- /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 000000000000..39d4bdb5acd3 --- /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 000000000000..e84c88904f6e --- /dev/null +++ b/third_party/rust/serde_bytes/README.md @@ -0,0 +1,55 @@ +# 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`. + +Without specialization, Rust forces Serde to treat `&[u8]` just like any +other slice and `Vec` 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` by wrapping it +in `serde_bytes::ByteBuf`. + +This crate supports the Serde `with` attribute to enable efficient handling +of `&[u8]` and `Vec` in structs without needing a wrapper type. + +```rust +#[macro_use] +extern crate serde_derive; + +extern crate serde; +extern crate serde_bytes; + +#[derive(Serialize)] +struct Efficient<'a> { + #[serde(with = "serde_bytes")] + bytes: &'a [u8], + + #[serde(with = "serde_bytes")] + byte_buf: Vec, +} + +#[derive(Serialize, Deserialize)] +struct Packet { + #[serde(with = "serde_bytes")] + payload: Vec, +} +``` + +## License + +Serde is licensed under either of + + * Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or + http://www.apache.org/licenses/LICENSE-2.0) + * MIT license ([LICENSE-MIT](LICENSE-MIT) or + http://opensource.org/licenses/MIT) + +at your option. + +### Contribution + +Unless you explicitly state otherwise, any contribution intentionally submitted +for inclusion in Serde by you, as defined in the Apache-2.0 license, shall be +dual licensed as above, without any additional terms or conditions. 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 000000000000..2686cd476595 --- /dev/null +++ b/third_party/rust/serde_bytes/src/lib.rs @@ -0,0 +1,431 @@ +//! Wrapper types to enable optimized handling of `&[u8]` and `Vec`. +//! +//! Without specialization, Rust forces Serde to treat `&[u8]` just like any +//! other slice and `Vec` 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` by wrapping it +//! in `serde_bytes::ByteBuf`. +//! +//! This crate supports the Serde `with` attribute to enable efficient handling +//! of `&[u8]` and `Vec` in structs without needing a wrapper type. +//! +//! ```rust +//! #[macro_use] +//! extern crate serde_derive; +//! +//! extern crate serde; +//! extern crate serde_bytes; +//! +//! #[derive(Serialize)] +//! struct Efficient<'a> { +//! #[serde(with = "serde_bytes")] +//! bytes: &'a [u8], +//! +//! #[serde(with = "serde_bytes")] +//! byte_buf: Vec, +//! } +//! +//! #[derive(Serialize, Deserialize)] +//! struct Packet { +//! #[serde(with = "serde_bytes")] +//! payload: Vec, +//! } +//! # +//! # fn main() {} +//! ``` + +#![doc(html_root_url = "https://docs.rs/serde_bytes/0.10.4")] +#![cfg_attr(not(feature = "std"), no_std)] +#![cfg_attr(feature = "alloc", feature(alloc))] +#![deny(missing_docs)] + +#[cfg(feature = "std")] +use std::{fmt, ops}; + +#[cfg(not(feature = "std"))] +use core::{fmt, ops}; + +use self::fmt::Debug; + +#[cfg(feature = "alloc")] +extern crate alloc; +#[cfg(feature = "alloc")] +use alloc::Vec; + +#[macro_use] +extern crate serde; +use serde::ser::{Serialize, Serializer}; +use serde::de::{Deserialize, Deserializer, Visitor, Error}; + +#[cfg(any(feature = "std", feature = "alloc"))] +pub use self::bytebuf::ByteBuf; + +mod value; + +////////////////////////////////////////////////////////////////////////////// + +/// 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")]` +/// +/// ```rust +/// #[macro_use] +/// extern crate serde_derive; +/// +/// extern crate serde; +/// extern crate serde_bytes; +/// +/// #[derive(Serialize)] +/// struct Efficient<'a> { +/// #[serde(with = "serde_bytes")] +/// bytes: &'a [u8], +/// +/// #[serde(with = "serde_bytes")] +/// byte_buf: Vec, +/// } +/// # +/// # fn main() {} +/// ``` +pub fn serialize(bytes: &T, serializer: S) -> Result + where T: ?Sized + AsRef<[u8]>, + S: Serializer +{ + serializer.serialize_bytes(bytes.as_ref()) +} + +/// 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")]` +/// +/// ```rust +/// #[macro_use] +/// extern crate serde_derive; +/// +/// extern crate serde; +/// extern crate serde_bytes; +/// +/// #[derive(Deserialize)] +/// struct Packet { +/// #[serde(with = "serde_bytes")] +/// payload: Vec, +/// } +/// # +/// # fn main() {} +/// ``` +#[cfg(any(feature = "std", feature = "alloc"))] +pub fn deserialize<'de, T, D>(deserializer: D) -> Result + where T: From>, + D: Deserializer<'de> +{ + ByteBuf::deserialize(deserializer).map(|buf| Into::>::into(buf).into()) +} + +////////////////////////////////////////////////////////////////////////////// + +/// Wrapper around `&[u8]` to serialize and deserialize efficiently. +/// +/// ```rust +/// extern crate bincode; +/// extern crate serde_bytes; +/// +/// use std::collections::HashMap; +/// use std::io; +/// +/// use serde_bytes::Bytes; +/// +/// fn print_encoded_cache() -> Result<(), bincode::Error> { +/// 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, bincode::Infinite) +/// } +/// # +/// # fn main() { +/// # print_encoded_cache().unwrap(); +/// # } +/// ``` +#[derive(Clone, Copy, Eq, Hash, PartialEq, PartialOrd, Ord)] +pub struct Bytes<'a> { + bytes: &'a [u8], +} + +impl<'a> Bytes<'a> { + /// Wrap an existing `&[u8]`. + pub fn new(bytes: &'a [u8]) -> Self { + Bytes { bytes: bytes } + } +} + +impl<'a> Debug for Bytes<'a> { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + Debug::fmt(self.bytes, f) + } +} + +impl<'a> From<&'a [u8]> for Bytes<'a> { + fn from(bytes: &'a [u8]) -> Self { + Bytes::new(bytes) + } +} + +impl<'a> From> for &'a [u8] { + fn from(wrapper: Bytes<'a>) -> &'a [u8] { + wrapper.bytes + } +} + +impl<'a> ops::Deref for Bytes<'a> { + type Target = [u8]; + + fn deref(&self) -> &[u8] { + self.bytes + } +} + +impl<'a> Serialize for Bytes<'a> { + #[inline] + fn serialize(&self, serializer: S) -> Result + where S: Serializer + { + serializer.serialize_bytes(self.bytes) + } +} + +struct BytesVisitor; + +impl<'de> Visitor<'de> for BytesVisitor { + type Value = Bytes<'de>; + + fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { + formatter.write_str("a borrowed byte array") + } + + #[inline] + fn visit_borrowed_bytes(self, v: &'de [u8]) -> Result, E> + where E: Error + { + Ok(Bytes::from(v)) + } + + #[inline] + fn visit_borrowed_str(self, v: &'de str) -> Result, E> + where E: Error + { + Ok(Bytes::from(v.as_bytes())) + } +} + +impl<'a, 'de: 'a> Deserialize<'de> for Bytes<'a> { + #[inline] + fn deserialize(deserializer: D) -> Result, D::Error> + where D: Deserializer<'de> + { + deserializer.deserialize_bytes(BytesVisitor) + } +} + +////////////////////////////////////////////////////////////////////////////// + +#[cfg(any(feature = "std", feature = "alloc"))] +mod bytebuf { + #[cfg(feature = "std")] + use std::{cmp, fmt, ops}; + + #[cfg(not(feature = "std"))] + use core::{cmp, fmt, ops}; + + use self::fmt::Debug; + + #[cfg(feature = "alloc")] + use alloc::{String, Vec}; + + use serde::ser::{Serialize, Serializer}; + use serde::de::{Deserialize, Deserializer, Visitor, SeqAccess, Error}; + + /// Wrapper around `Vec` to serialize and deserialize efficiently. + /// + /// ```rust + /// extern crate bincode; + /// extern crate serde_bytes; + /// + /// use std::collections::HashMap; + /// use std::io; + /// + /// use serde_bytes::ByteBuf; + /// + /// fn deserialize_bytebufs() -> Result<(), bincode::Error> { + /// 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 = + /// bincode::deserialize_from(&mut &example_data[..], bincode::Infinite)?; + /// + /// println!("{:?}", map); + /// + /// Ok(()) + /// } + /// # + /// # fn main() { + /// # deserialize_bytebufs().unwrap(); + /// # } + /// ``` + #[derive(Clone, Default, Eq, Hash, PartialEq, PartialOrd, Ord)] + pub struct ByteBuf { + bytes: Vec, + } + + 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>>(bytes: T) -> Self { + ByteBuf { bytes: bytes.into() } + } + } + + impl Debug for ByteBuf { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + Debug::fmt(&self.bytes, f) + } + } + + impl From for Vec { + fn from(wrapper: ByteBuf) -> Vec { + wrapper.bytes + } + } + + impl From> for ByteBuf { + fn from(bytes: Vec) -> Self { + ByteBuf::from(bytes) + } + } + + impl AsRef> for ByteBuf { + fn as_ref(&self) -> &Vec { + &self.bytes + } + } + + impl AsRef<[u8]> for ByteBuf { + fn as_ref(&self) -> &[u8] { + &self.bytes + } + } + + impl AsMut> for ByteBuf { + fn as_mut(&mut self) -> &mut Vec { + &mut self.bytes + } + } + + impl AsMut<[u8]> for ByteBuf { + fn as_mut(&mut self) -> &mut [u8] { + &mut self.bytes + } + } + + impl ops::Deref for ByteBuf { + type Target = [u8]; + + fn deref(&self) -> &[u8] { + &self.bytes[..] + } + } + + impl ops::DerefMut for ByteBuf { + fn deref_mut(&mut self) -> &mut [u8] { + &mut self.bytes[..] + } + } + + impl Serialize for ByteBuf { + #[inline] + fn serialize(&self, serializer: S) -> Result + 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") + } + + #[inline] + fn visit_seq(self, mut visitor: V) -> Result + 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) = try!(visitor.next_element()) { + values.push(value); + } + + Ok(ByteBuf::from(values)) + } + + #[inline] + fn visit_bytes(self, v: &[u8]) -> Result + where E: Error + { + Ok(ByteBuf::from(v)) + } + + #[inline] + fn visit_byte_buf(self, v: Vec) -> Result + where E: Error + { + Ok(ByteBuf::from(v)) + } + + #[inline] + fn visit_str(self, v: &str) -> Result + where E: Error + { + Ok(ByteBuf::from(v)) + } + + #[inline] + fn visit_string(self, v: String) -> Result + where E: Error + { + Ok(ByteBuf::from(v)) + } + } + + impl<'de> Deserialize<'de> for ByteBuf { + #[inline] + fn deserialize(deserializer: D) -> Result + where D: Deserializer<'de> + { + deserializer.deserialize_byte_buf(ByteBufVisitor) + } + } +} diff --git a/third_party/rust/serde_bytes/src/value.rs b/third_party/rust/serde_bytes/src/value.rs new file mode 100644 index 000000000000..2699cc720ee3 --- /dev/null +++ b/third_party/rust/serde_bytes/src/value.rs @@ -0,0 +1,91 @@ +use serde::de::{Deserializer, IntoDeserializer, Visitor, Error}; + +#[cfg(feature = "std")] +use std::marker::PhantomData; + +#[cfg(not(feature = "std"))] +use core::marker::PhantomData; + +#[cfg(feature = "alloc")] +use alloc::Vec; + +////////////////////////////////////////////////////////////////////////////// + +impl<'de, 'a, E> IntoDeserializer<'de, E> for super::Bytes<'a> + where E: Error +{ + type Deserializer = BytesDeserializer<'a, E>; + + fn into_deserializer(self) -> Self::Deserializer { + BytesDeserializer { + value: self.into(), + error: PhantomData, + } + } +} + +/// A deserializer that deserializes a `&[u8]`. +pub struct BytesDeserializer<'a, E> { + value: &'a [u8], + error: PhantomData, +} + +impl<'de, 'a, E> Deserializer<'de> for BytesDeserializer<'a, E> + where E: Error +{ + type Error = E; + + fn deserialize_any(self, visitor: V) -> Result + where V: Visitor<'de> + { + visitor.visit_bytes(self.value) + } + + forward_to_deserialize_any! { + bool i8 i16 i32 i64 u8 u16 u32 u64 f32 f64 char str string bytes + byte_buf option unit unit_struct newtype_struct seq tuple + tuple_struct map struct enum identifier ignored_any + } +} + +////////////////////////////////////////////////////////////////////////////// + +#[cfg(any(feature = "std", feature = "alloc"))] +impl<'de, E> IntoDeserializer<'de, E> for super::ByteBuf + where E: Error +{ + type Deserializer = ByteBufDeserializer; + + fn into_deserializer(self) -> Self::Deserializer { + ByteBufDeserializer { + value: self.into(), + error: PhantomData, + } + } +} + +/// A deserializer that deserializes a `Vec`. +#[cfg(any(feature = "std", feature = "alloc"))] +pub struct ByteBufDeserializer { + value: Vec, + error: PhantomData, +} + +#[cfg(any(feature = "std", feature = "alloc"))] +impl<'de, E> Deserializer<'de> for ByteBufDeserializer + where E: Error +{ + type Error = E; + + fn deserialize_any(self, visitor: V) -> Result + where V: Visitor<'de> + { + visitor.visit_byte_buf(self.value) + } + + forward_to_deserialize_any! { + bool i8 i16 i32 i64 u8 u16 u32 u64 f32 f64 char str string bytes + byte_buf option unit unit_struct newtype_struct seq tuple + tuple_struct map struct enum identifier ignored_any + } +}