RPM build fix (reverted CI changes which will need to be un-reverted or made conditional) and vendor Rust dependencies to make builds much faster in any CI system.
This commit is contained in:
1
zeroidc/vendor/tinyvec/.cargo-checksum.json
vendored
Normal file
1
zeroidc/vendor/tinyvec/.cargo-checksum.json
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"files":{"CHANGELOG.md":"ba1670e87d405d529ed865529527f8ed4745dc9e546b2261a977f39f5e22fc0a","Cargo.toml":"1d9f89358780ead10a883bea408af7271561f074bedb8e5755c3136182c170f4","LICENSE-APACHE.md":"3ddf9be5c28fe27dad143a5dc76eea25222ad1dd68934a047064e56ed2fa40c5","LICENSE-MIT.md":"4736b5d379253afa45744afc79ddb475912b213e939bdf7cb97d9a8b6f700e5f","LICENSE-ZLIB.md":"682b4c81b85e83ce6cc6e1ace38fdd97aeb4de0e972bd2b44aa0916c54af8c96","README.md":"f2a59c75ef204e21173b2be150d183a946d0f10ad3a42d3e677d6f5507589aa4","benches/macros.rs":"b92679a63e1d39fd949c061fa97dfba933f3e1a6e6722e710cfe4fbfd6315ba9","benches/smallvec.rs":"977761721e1b419966441a767f9eed23b82e6f805e0d496b9905d225600fc050","compare_benchmarks.py":"899f3d88c95f0f02563f869fd683a9c95afb1a8c773edf2d0a8d3355f1ceb07c","gen-array-impls.sh":"6bb75d48b820112b7d0a67e09fb3c2386b2961de42f482635007435956f74b12","rustfmt.toml":"ebb19c2c422dcc6c0fe960e5a869b5a562739e40f248e28c43d48d9a63cebe7b","src-backup/arrayset.rs":"d7d524c9c0a20443f6f028ff0e37d246cd445a0660df496625d647ea302a5094","src/array.rs":"ae2bc64b339ff3e8a17684b25a180fbf04184cae26baf05fb8ed542005f6d9f5","src/array/const_generic_impl.rs":"d0f8ae529b5c9f92da0aa67d5ae24a6e7fc3287ce6d3e576794455de44502a4c","src/array/generated_impl.rs":"8c94c274aae0909b7de75beff4215af8dfc8635cce0c09d75eb57e577c3cca68","src/arrayvec.rs":"349395049164b38f6d8ad9fda8ed925855955cf348b087c796fb9113c1d25687","src/arrayvec_drain.rs":"d2df895c7438bbf3bcf2f68ab5e76ca2209f399ef8dde5d62532c9e176c620b5","src/lib.rs":"867817c74c52316ffdea3a7a7cdf8285cadebe63cf63fb966aafd8130f796db4","src/slicevec.rs":"e43991aff8197095fda62a1e6d3657fcb08e27e386e67f0496ac8228a56bd271","src/tinyvec.rs":"a58c5b8e52619476da195c060a867d99ee0881bdd9e8eeabad947ee949b858af","tests/arrayvec.rs":"e7c22cbcf8df2c0a5ae20a35c1a1327e86230db0ee6fbc25d3ff5000b0044ccc","tests/tinyvec.rs":"8f61a29426ac573999e6328a1bd74d7bc19884b3e38dcfda0a254dc91c1d2310"},"package":"87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50"}
|
||||
73
zeroidc/vendor/tinyvec/CHANGELOG.md
vendored
Normal file
73
zeroidc/vendor/tinyvec/CHANGELOG.md
vendored
Normal file
@@ -0,0 +1,73 @@
|
||||
# Changelog
|
||||
|
||||
## 1.6.0
|
||||
|
||||
* [i509VCB](https://github.com/i509VCB) added the `try_` functions for fallable reallocation.
|
||||
[pr 158](https://github.com/Lokathor/tinyvec/pull/158)
|
||||
* [ajtribick](https://github.com/ajtribick) added more error impls to `TryFromSliceError`.
|
||||
[pr 160](https://github.com/Lokathor/tinyvec/pull/160)
|
||||
* The `std` feature now automatically enables the `alloc` feature as well.
|
||||
|
||||
## 1.5.1
|
||||
|
||||
* [madsmtm](https://github.com/madsmtm) fixed an error with the `alloc` feature on very old rustc versions.
|
||||
[pr 154](https://github.com/Lokathor/tinyvec/pull/154)
|
||||
|
||||
## 1.5.0
|
||||
|
||||
* [eeeebbbbrrrr](https://github.com/eeeebbbbrrrr) added an impl for [std::io::Write](https://doc.rust-lang.org/std/io/trait.Write.html) to `TinyVec` when the element type is `u8`.
|
||||
This is gated behind the new `std` feature.
|
||||
[pr 152](https://github.com/Lokathor/tinyvec/pull/152)
|
||||
|
||||
## 1.4.0
|
||||
|
||||
* [saethlin](https://github.com/saethlin) stabilized the usage of const generics and array map with the `rustc_1_55` feature.
|
||||
[pr 149](https://github.com/Lokathor/tinyvec/pull/149)
|
||||
|
||||
## 1.3.1
|
||||
|
||||
* Improved the performance of the `clone_from` method [pr 144](https://github.com/Lokathor/tinyvec/pull/144)
|
||||
|
||||
## 1.3.0
|
||||
|
||||
* [jeffa5](https://github.com/jeffa5) added arbitrary implementations for `TinyVec` and `ArrayVec` [pr 146](https://github.com/Lokathor/tinyvec/pull/146).
|
||||
* [elomatreb](https://github.com/elomatreb) implemented `DoubleEndedIterator` for `TinyVecIterator` [pr 145](https://github.com/Lokathor/tinyvec/pull/145).
|
||||
|
||||
## 1.2.0
|
||||
|
||||
* [Cryptjar](https://github.com/Cryptjar) removed the `A:Array` bound on the struct of `ArrayVec<A:Array>`,
|
||||
and added the `from_array_empty` method, which is a `const fn` constructor
|
||||
[pr 141](https://github.com/Lokathor/tinyvec/pull/141).
|
||||
|
||||
## 1.1.1
|
||||
|
||||
* [saethlin](https://github.com/saethlin) contributed many PRs (
|
||||
[127](https://github.com/Lokathor/tinyvec/pull/127),
|
||||
[128](https://github.com/Lokathor/tinyvec/pull/128),
|
||||
[129](https://github.com/Lokathor/tinyvec/pull/129),
|
||||
[131](https://github.com/Lokathor/tinyvec/pull/131),
|
||||
[132](https://github.com/Lokathor/tinyvec/pull/132)
|
||||
) to help in several benchmarks.
|
||||
|
||||
## 1.1.0
|
||||
|
||||
* [slightlyoutofphase](https://github.com/slightlyoutofphase)
|
||||
added "array splat" style syntax to the `array_vec!` and `tiny_vec!` macros.
|
||||
You can now write `array_vec![true; 5]` and get a length 5 array vec full of `true`,
|
||||
just like normal array initialization allows. Same goes for `tiny_vec!`.
|
||||
([pr 118](https://github.com/Lokathor/tinyvec/pull/118))
|
||||
* [not-a-seagull](https://github.com/not-a-seagull)
|
||||
added `ArrayVec::into_inner` so that you can get the array out of an `ArrayVec`.
|
||||
([pr 124](https://github.com/Lokathor/tinyvec/pull/124))
|
||||
|
||||
## 1.0.2
|
||||
|
||||
* Added license files for the MIT and Apache-2.0 license options.
|
||||
|
||||
## 1.0.1
|
||||
|
||||
* Display additional features in the [docs.rs/tinyvec](https://docs.rs/tinyvec) documentation.
|
||||
|
||||
## 1.0.0
|
||||
|
||||
Initial Stable Release.
|
||||
113
zeroidc/vendor/tinyvec/Cargo.toml
vendored
Normal file
113
zeroidc/vendor/tinyvec/Cargo.toml
vendored
Normal file
@@ -0,0 +1,113 @@
|
||||
# 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 are reading this file be aware that the original Cargo.toml
|
||||
# will likely look very different (and much more reasonable).
|
||||
# See Cargo.toml.orig for the original contents.
|
||||
|
||||
[package]
|
||||
edition = "2018"
|
||||
name = "tinyvec"
|
||||
version = "1.6.0"
|
||||
authors = ["Lokathor <zefria@gmail.com>"]
|
||||
description = "`tinyvec` provides 100% safe vec-like data structures."
|
||||
readme = "README.md"
|
||||
keywords = [
|
||||
"vec",
|
||||
"no_std",
|
||||
"no-std",
|
||||
]
|
||||
categories = [
|
||||
"data-structures",
|
||||
"no-std",
|
||||
]
|
||||
license = "Zlib OR Apache-2.0 OR MIT"
|
||||
repository = "https://github.com/Lokathor/tinyvec"
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
features = [
|
||||
"alloc",
|
||||
"std",
|
||||
"grab_spare_slice",
|
||||
"rustc_1_40",
|
||||
"rustc_1_55",
|
||||
"serde",
|
||||
]
|
||||
rustdoc-args = [
|
||||
"--cfg",
|
||||
"docs_rs",
|
||||
]
|
||||
|
||||
[package.metadata.playground]
|
||||
features = [
|
||||
"alloc",
|
||||
"std",
|
||||
"grab_spare_slice",
|
||||
"rustc_1_40",
|
||||
"rustc_1_55",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[profile.bench]
|
||||
debug = 2
|
||||
|
||||
[profile.test]
|
||||
opt-level = 3
|
||||
|
||||
[[test]]
|
||||
name = "tinyvec"
|
||||
required-features = [
|
||||
"alloc",
|
||||
"std",
|
||||
]
|
||||
|
||||
[[bench]]
|
||||
name = "macros"
|
||||
harness = false
|
||||
required-features = ["alloc"]
|
||||
|
||||
[[bench]]
|
||||
name = "smallvec"
|
||||
harness = false
|
||||
required-features = [
|
||||
"alloc",
|
||||
"real_blackbox",
|
||||
]
|
||||
|
||||
[dependencies.arbitrary]
|
||||
version = "1"
|
||||
optional = true
|
||||
|
||||
[dependencies.serde]
|
||||
version = "1.0"
|
||||
optional = true
|
||||
default-features = false
|
||||
|
||||
[dependencies.tinyvec_macros]
|
||||
version = "0.1"
|
||||
optional = true
|
||||
|
||||
[dev-dependencies.criterion]
|
||||
version = "0.3.0"
|
||||
|
||||
[dev-dependencies.serde_test]
|
||||
version = "1.0"
|
||||
|
||||
[dev-dependencies.smallvec]
|
||||
version = "1"
|
||||
|
||||
[features]
|
||||
alloc = ["tinyvec_macros"]
|
||||
default = []
|
||||
experimental_write_impl = []
|
||||
grab_spare_slice = []
|
||||
nightly_slice_partition_dedup = []
|
||||
real_blackbox = ["criterion/real_blackbox"]
|
||||
rustc_1_40 = []
|
||||
rustc_1_55 = ["rustc_1_40"]
|
||||
rustc_1_57 = ["rustc_1_55"]
|
||||
std = ["alloc"]
|
||||
202
zeroidc/vendor/tinyvec/LICENSE-APACHE.md
vendored
Normal file
202
zeroidc/vendor/tinyvec/LICENSE-APACHE.md
vendored
Normal file
@@ -0,0 +1,202 @@
|
||||
|
||||
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.
|
||||
5
zeroidc/vendor/tinyvec/LICENSE-MIT.md
vendored
Normal file
5
zeroidc/vendor/tinyvec/LICENSE-MIT.md
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
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.
|
||||
11
zeroidc/vendor/tinyvec/LICENSE-ZLIB.md
vendored
Normal file
11
zeroidc/vendor/tinyvec/LICENSE-ZLIB.md
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
Copyright (c) 2019 Daniel "Lokathor" Gee.
|
||||
|
||||
This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
||||
|
||||
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
||||
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
19
zeroidc/vendor/tinyvec/README.md
vendored
Normal file
19
zeroidc/vendor/tinyvec/README.md
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
[](https://opensource.org/licenses/Zlib)
|
||||

|
||||
[](https://crates.io/crates/tinyvec)
|
||||
[](https://docs.rs/tinyvec/)
|
||||
|
||||

|
||||
|
||||
# tinyvec
|
||||
|
||||
A 100% safe crate of vec-like types. `#![forbid(unsafe_code)]`
|
||||
|
||||
Main types are as follows:
|
||||
* `ArrayVec` is an array-backed vec-like data structure. It panics on overflow.
|
||||
* `SliceVec` is the same deal, but using a `&mut [T]`.
|
||||
* `TinyVec` (`alloc` feature) is an enum that's either an `Inline(ArrayVec)` or a `Heap(Vec)`. If a `TinyVec` is `Inline` and would overflow it automatically transitions to `Heap` and continues whatever it was doing.
|
||||
|
||||
To attain this "100% safe code" status there is one compromise: the element type of the vecs must implement `Default`.
|
||||
|
||||
For more details, please see [the docs.rs documentation](https://docs.rs/tinyvec/)
|
||||
52
zeroidc/vendor/tinyvec/benches/macros.rs
vendored
Normal file
52
zeroidc/vendor/tinyvec/benches/macros.rs
vendored
Normal file
@@ -0,0 +1,52 @@
|
||||
use criterion::{criterion_group, criterion_main, Criterion};
|
||||
|
||||
use tinyvec::tiny_vec;
|
||||
|
||||
fn bench_tinyvec_macro(c: &mut Criterion) {
|
||||
let mut g = c.benchmark_group("tinyvec_macro");
|
||||
|
||||
g.bench_function("0 of 32", |b| {
|
||||
b.iter(|| tiny_vec!([u8; 32]));
|
||||
});
|
||||
|
||||
g.bench_function("16 of 32", |b| {
|
||||
b.iter(|| {
|
||||
tiny_vec!([u8; 32]=>
|
||||
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
|
||||
)
|
||||
});
|
||||
});
|
||||
|
||||
g.bench_function("32 of 32", |b| {
|
||||
b.iter(|| {
|
||||
tiny_vec!([u8; 32]=>
|
||||
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
|
||||
17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32,
|
||||
)
|
||||
});
|
||||
});
|
||||
|
||||
g.bench_function("33 of 32", |b| {
|
||||
b.iter(|| {
|
||||
tiny_vec!([u8; 32]=>
|
||||
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
|
||||
17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32,
|
||||
33,
|
||||
)
|
||||
});
|
||||
});
|
||||
|
||||
g.bench_function("64 of 32", |b| {
|
||||
b.iter(|| {
|
||||
tiny_vec!([u8; 32]=>
|
||||
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
|
||||
17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32,
|
||||
33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48,
|
||||
49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64,
|
||||
)
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
criterion_group!(benches, bench_tinyvec_macro);
|
||||
criterion_main!(benches);
|
||||
500
zeroidc/vendor/tinyvec/benches/smallvec.rs
vendored
Normal file
500
zeroidc/vendor/tinyvec/benches/smallvec.rs
vendored
Normal file
@@ -0,0 +1,500 @@
|
||||
//! Benchmarks that compare TinyVec to SmallVec
|
||||
//!
|
||||
//! All the following commentary is based on the latest nightly at the time:
|
||||
//! rustc 1.55.0 (c8dfcfe04 2021-09-06).
|
||||
//!
|
||||
//! Some of these benchmarks are just a few instructions, so we put our own for loop inside
|
||||
//! the criterion::Bencher::iter call. This seems to improve the stability of measurements, and it
|
||||
//! has the wonderful side effect of making the emitted assembly easier to follow. Some of these
|
||||
//! benchmarks are totally inlined so that there are no calls at all in the hot path, so finding
|
||||
//! this for loop is an easy way to find your way around the emitted assembly.
|
||||
//!
|
||||
//! The clear method is cheaper to call for arrays of elements without a Drop impl, so wherever
|
||||
//! possible we reuse a single object in the benchmark loop, with a clear + black_box on each
|
||||
//! iteration in an attempt to not make that visible to the optimizer.
|
||||
//!
|
||||
//! We always call black_box(&v), instead of v = black_box(v) because the latter does a move of the
|
||||
//! inline array, which is linear in the size of the array and thus varies based on the array type
|
||||
//! being benchmarked, and this move can be more expensive than the function we're trying to
|
||||
//! benchmark.
|
||||
//!
|
||||
//! We also black_box the input to each method call. This has a significant effect on the assembly
|
||||
//! emitted, for example if we do not black_box the range we iterate over in the ::push benchmarks,
|
||||
//! the loop is unrolled. It's not entirely clear if it's better to black_box the iterator that
|
||||
//! yields the items being pushed, or to black_box at a deeper level: v.push(black_box(i)) for
|
||||
//! example. Anecdotally, it seems like the latter approach produces unreasonably bad assembly.
|
||||
//!
|
||||
|
||||
use criterion::{black_box, criterion_group, criterion_main, Criterion};
|
||||
use smallvec::SmallVec;
|
||||
use std::iter::FromIterator;
|
||||
use tinyvec::TinyVec;
|
||||
|
||||
const ITERS: usize = 10_000;
|
||||
|
||||
macro_rules! tinyvec_benches {
|
||||
($c:expr, $type:ty ; $len:expr) => {{
|
||||
let mut g = $c.benchmark_group(concat!(
|
||||
"TinyVec_",
|
||||
stringify!($type),
|
||||
"_",
|
||||
stringify!($len)
|
||||
));
|
||||
|
||||
g.bench_function(
|
||||
concat!(
|
||||
"TinyVec<[",
|
||||
stringify!($type),
|
||||
"; ",
|
||||
stringify!($len),
|
||||
"]>::default"
|
||||
),
|
||||
|b| {
|
||||
b.iter(|| {
|
||||
for _ in 0..ITERS {
|
||||
let v: TinyVec<[$type; $len]> = TinyVec::default();
|
||||
black_box(&v);
|
||||
}
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
g.bench_function(
|
||||
concat!(
|
||||
"TinyVec<[",
|
||||
stringify!($type),
|
||||
"; ",
|
||||
stringify!($len),
|
||||
"]>::clone"
|
||||
),
|
||||
|b| {
|
||||
b.iter(|| {
|
||||
let outer: TinyVec<[$type; $len]> =
|
||||
black_box(TinyVec::from_iter(0..=($len as usize - 1) as _));
|
||||
for _ in 0..ITERS {
|
||||
let v = outer.clone();
|
||||
black_box(&v);
|
||||
}
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
g.bench_function(
|
||||
concat!(
|
||||
"TinyVec<[",
|
||||
stringify!($type),
|
||||
"; ",
|
||||
stringify!($len),
|
||||
"]>::clear"
|
||||
),
|
||||
|b| {
|
||||
b.iter(|| {
|
||||
let mut v: TinyVec<[$type; $len]> = TinyVec::default();
|
||||
for _ in 0..ITERS {
|
||||
v.clear();
|
||||
black_box(&v);
|
||||
}
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
g.bench_function(
|
||||
concat!(
|
||||
"TinyVec<[",
|
||||
stringify!($type),
|
||||
"; ",
|
||||
stringify!($len),
|
||||
"]>::push"
|
||||
),
|
||||
|b| {
|
||||
b.iter(|| {
|
||||
let mut v: TinyVec<[$type; $len]> = TinyVec::default();
|
||||
for _ in 0..ITERS {
|
||||
v.clear();
|
||||
black_box(&v);
|
||||
for i in black_box(0..=($len as usize - 1) as _) {
|
||||
v.push(i);
|
||||
}
|
||||
black_box(&v);
|
||||
}
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
g.bench_function(
|
||||
concat!(
|
||||
"TinyVec<[",
|
||||
stringify!($type),
|
||||
"; ",
|
||||
stringify!($len),
|
||||
"]>::from_iter"
|
||||
),
|
||||
|b| {
|
||||
b.iter(|| {
|
||||
for _ in 0..ITERS {
|
||||
let v: TinyVec<[$type; $len]> =
|
||||
TinyVec::from_iter(black_box(0..=($len as usize - 1) as _));
|
||||
black_box(&v);
|
||||
}
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
g.bench_function(
|
||||
concat!(
|
||||
"TinyVec<[",
|
||||
stringify!($type),
|
||||
"; ",
|
||||
stringify!($len),
|
||||
"]>::from_slice"
|
||||
),
|
||||
|b| {
|
||||
b.iter(|| {
|
||||
let data: &[$type] = &[0, 1, 2, 3, 4, 5, 6, 7];
|
||||
for _ in 0..ITERS {
|
||||
let v: TinyVec<[$type; $len]> = TinyVec::from(black_box(data));
|
||||
black_box(&v);
|
||||
}
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
g.bench_function(
|
||||
concat!(
|
||||
"TinyVec<[",
|
||||
stringify!($type),
|
||||
"; ",
|
||||
stringify!($len),
|
||||
"]>::extend"
|
||||
),
|
||||
|b| {
|
||||
b.iter(|| {
|
||||
let mut v: TinyVec<[$type; $len]> = black_box(TinyVec::default());
|
||||
for _ in 0..ITERS {
|
||||
v.clear();
|
||||
black_box(&v);
|
||||
v.extend(black_box(0..=($len as usize - 1) as _));
|
||||
black_box(&v);
|
||||
}
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
g.bench_function(
|
||||
concat!(
|
||||
"TinyVec<[",
|
||||
stringify!($type),
|
||||
"; ",
|
||||
stringify!($len),
|
||||
"]>::extend_from_slice"
|
||||
),
|
||||
|b| {
|
||||
b.iter(|| {
|
||||
let data: &[$type] = black_box(&[0, 1, 2, 3, 4, 5, 6, 7]);
|
||||
let mut v: TinyVec<[$type; $len]> = black_box(TinyVec::default());
|
||||
for _ in 0..ITERS {
|
||||
v.clear();
|
||||
black_box(&v);
|
||||
v.extend_from_slice(data);
|
||||
black_box(&v);
|
||||
}
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
g.bench_function(
|
||||
concat!(
|
||||
"TinyVec<[",
|
||||
stringify!($type),
|
||||
"; ",
|
||||
stringify!($len),
|
||||
"]>::insert"
|
||||
),
|
||||
|b| {
|
||||
b.iter(|| {
|
||||
let mut v: TinyVec<[$type; $len]> = TinyVec::default();
|
||||
for _ in 0..ITERS {
|
||||
v.clear();
|
||||
black_box(&v);
|
||||
for i in black_box(0..=($len as usize - 1) as _) {
|
||||
v.insert(i as usize, i);
|
||||
}
|
||||
black_box(&v);
|
||||
}
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
g.bench_function(
|
||||
concat!(
|
||||
"TinyVec<[",
|
||||
stringify!($type),
|
||||
"; ",
|
||||
stringify!($len),
|
||||
"]>::remove"
|
||||
),
|
||||
|b| {
|
||||
b.iter(|| {
|
||||
let outer: TinyVec<[$type; $len]> =
|
||||
black_box(TinyVec::from_iter(0..=($len as usize - 1) as _));
|
||||
for _ in 0..ITERS {
|
||||
let mut v = outer.clone();
|
||||
for i in black_box((0..=($len as usize - 1) as _).rev()) {
|
||||
v.remove(i);
|
||||
}
|
||||
black_box(&v);
|
||||
}
|
||||
});
|
||||
},
|
||||
);
|
||||
}};
|
||||
}
|
||||
|
||||
fn tinyvec_benches(c: &mut Criterion) {
|
||||
tinyvec_benches!(c, u8; 8);
|
||||
tinyvec_benches!(c, u8; 16);
|
||||
tinyvec_benches!(c, u8; 32);
|
||||
tinyvec_benches!(c, u8; 64);
|
||||
tinyvec_benches!(c, u8; 128);
|
||||
tinyvec_benches!(c, u8; 256);
|
||||
tinyvec_benches!(c, u64; 2);
|
||||
tinyvec_benches!(c, u64; 4);
|
||||
tinyvec_benches!(c, u64; 8);
|
||||
tinyvec_benches!(c, u64; 16);
|
||||
tinyvec_benches!(c, u64; 32);
|
||||
}
|
||||
|
||||
macro_rules! smallvec_benches {
|
||||
($c:expr, $type:ty ; $len:expr) => {{
|
||||
let mut g = $c.benchmark_group(concat!(
|
||||
"SmallVec_",
|
||||
stringify!($type),
|
||||
"_",
|
||||
stringify!($len)
|
||||
));
|
||||
|
||||
g.bench_function(
|
||||
concat!(
|
||||
"SmallVec<[",
|
||||
stringify!($type),
|
||||
"; ",
|
||||
stringify!($len),
|
||||
"]>::default"
|
||||
),
|
||||
|b| {
|
||||
b.iter(|| {
|
||||
for _ in 0..ITERS {
|
||||
let v: SmallVec<[$type; $len]> = SmallVec::default();
|
||||
black_box(&v);
|
||||
}
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
g.bench_function(
|
||||
concat!(
|
||||
"SmallVec<[",
|
||||
stringify!($type),
|
||||
"; ",
|
||||
stringify!($len),
|
||||
"]>::clone"
|
||||
),
|
||||
|b| {
|
||||
b.iter(|| {
|
||||
let outer: SmallVec<[$type; $len]> =
|
||||
black_box(SmallVec::from_iter(0..=($len as usize - 1) as _));
|
||||
for _ in 0..ITERS {
|
||||
let v = outer.clone();
|
||||
black_box(&v);
|
||||
}
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
g.bench_function(
|
||||
concat!(
|
||||
"SmallVec<[",
|
||||
stringify!($type),
|
||||
"; ",
|
||||
stringify!($len),
|
||||
"]>::clear"
|
||||
),
|
||||
|b| {
|
||||
b.iter(|| {
|
||||
let mut v: SmallVec<[$type; $len]> = SmallVec::default();
|
||||
for _ in 0..ITERS {
|
||||
v.clear();
|
||||
black_box(&v);
|
||||
}
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
g.bench_function(
|
||||
concat!(
|
||||
"SmallVec<[",
|
||||
stringify!($type),
|
||||
"; ",
|
||||
stringify!($len),
|
||||
"]>::push"
|
||||
),
|
||||
|b| {
|
||||
b.iter(|| {
|
||||
let mut v: SmallVec<[$type; $len]> = SmallVec::default();
|
||||
for _ in 0..ITERS {
|
||||
v.clear();
|
||||
black_box(&v);
|
||||
for i in black_box(0..=($len as usize - 1) as _) {
|
||||
v.push(i);
|
||||
}
|
||||
black_box(&v);
|
||||
}
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
g.bench_function(
|
||||
concat!(
|
||||
"SmallVec<[",
|
||||
stringify!($type),
|
||||
"; ",
|
||||
stringify!($len),
|
||||
"]>::from_iter"
|
||||
),
|
||||
|b| {
|
||||
b.iter(|| {
|
||||
for _ in 0..ITERS {
|
||||
let v: SmallVec<[$type; $len]> =
|
||||
SmallVec::from_iter(black_box(0..=($len as usize - 1) as _));
|
||||
black_box(&v);
|
||||
}
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
g.bench_function(
|
||||
concat!(
|
||||
"SmallVec<[",
|
||||
stringify!($type),
|
||||
"; ",
|
||||
stringify!($len),
|
||||
"]>::from_slice"
|
||||
),
|
||||
|b| {
|
||||
b.iter(|| {
|
||||
let data: &[$type] = &[0, 1, 2, 3, 4, 5, 6, 7];
|
||||
for _ in 0..ITERS {
|
||||
let v: SmallVec<[$type; $len]> = SmallVec::from(black_box(data));
|
||||
black_box(&v);
|
||||
}
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
g.bench_function(
|
||||
concat!(
|
||||
"SmallVec<[",
|
||||
stringify!($type),
|
||||
"; ",
|
||||
stringify!($len),
|
||||
"]>::extend"
|
||||
),
|
||||
|b| {
|
||||
b.iter(|| {
|
||||
let mut v: SmallVec<[$type; $len]> = black_box(SmallVec::default());
|
||||
for _ in 0..ITERS {
|
||||
v.clear();
|
||||
black_box(&v);
|
||||
v.extend(black_box(0..=($len as usize - 1) as _));
|
||||
black_box(&v);
|
||||
}
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
g.bench_function(
|
||||
concat!(
|
||||
"SmallVec<[",
|
||||
stringify!($type),
|
||||
"; ",
|
||||
stringify!($len),
|
||||
"]>::extend_from_slice"
|
||||
),
|
||||
|b| {
|
||||
b.iter(|| {
|
||||
let data: &[$type] = black_box(&[0, 1, 2, 3, 4, 5, 6, 7]);
|
||||
let mut v: SmallVec<[$type; $len]> = black_box(SmallVec::default());
|
||||
for _ in 0..ITERS {
|
||||
v.clear();
|
||||
black_box(&v);
|
||||
v.extend_from_slice(data);
|
||||
black_box(&v);
|
||||
}
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
g.bench_function(
|
||||
concat!(
|
||||
"SmallVec<[",
|
||||
stringify!($type),
|
||||
"; ",
|
||||
stringify!($len),
|
||||
"]>::insert"
|
||||
),
|
||||
|b| {
|
||||
b.iter(|| {
|
||||
let mut v: SmallVec<[$type; $len]> = SmallVec::default();
|
||||
for _ in 0..ITERS {
|
||||
v.clear();
|
||||
black_box(&v);
|
||||
for i in black_box(0..=($len as usize - 1) as _) {
|
||||
v.insert(i as usize, i);
|
||||
}
|
||||
black_box(&v);
|
||||
}
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
g.bench_function(
|
||||
concat!(
|
||||
"SmallVec<[",
|
||||
stringify!($type),
|
||||
"; ",
|
||||
stringify!($len),
|
||||
"]>::remove"
|
||||
),
|
||||
|b| {
|
||||
b.iter(|| {
|
||||
let outer: SmallVec<[$type; $len]> =
|
||||
black_box(SmallVec::from_iter(0..=($len as usize - 1) as _));
|
||||
for _ in 0..ITERS {
|
||||
let mut v = outer.clone();
|
||||
for i in black_box((0..=($len as usize - 1) as _).rev()) {
|
||||
v.remove(i);
|
||||
}
|
||||
black_box(&v);
|
||||
}
|
||||
});
|
||||
},
|
||||
);
|
||||
}};
|
||||
}
|
||||
|
||||
fn smallvec_benches(c: &mut Criterion) {
|
||||
smallvec_benches!(c, u8; 8);
|
||||
smallvec_benches!(c, u8; 16);
|
||||
smallvec_benches!(c, u8; 32);
|
||||
smallvec_benches!(c, u8; 64);
|
||||
smallvec_benches!(c, u8; 128);
|
||||
smallvec_benches!(c, u8; 256);
|
||||
smallvec_benches!(c, u64; 2);
|
||||
smallvec_benches!(c, u64; 4);
|
||||
smallvec_benches!(c, u64; 8);
|
||||
smallvec_benches!(c, u64; 16);
|
||||
smallvec_benches!(c, u64; 32);
|
||||
}
|
||||
|
||||
criterion_group!(benches, tinyvec_benches, smallvec_benches);
|
||||
criterion_main!(benches);
|
||||
30
zeroidc/vendor/tinyvec/compare_benchmarks.py
vendored
Normal file
30
zeroidc/vendor/tinyvec/compare_benchmarks.py
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
import os
|
||||
import os.path
|
||||
import json
|
||||
|
||||
comparisons = []
|
||||
|
||||
for (root, _dirs, files) in os.walk('target/criterion'):
|
||||
for file in files:
|
||||
if file == 'estimates.json' and root.endswith(
|
||||
'new') and 'TinyVec' in root:
|
||||
path = os.path.join(root, file)
|
||||
|
||||
bench_name = path.split('/')[3]
|
||||
tinyvec_time = json.load(open(path))['mean']['point_estimate']
|
||||
|
||||
path = path.replace('TinyVec', 'SmallVec')
|
||||
|
||||
smallvec_time = json.load(open(path))['mean']['point_estimate']
|
||||
|
||||
comparisons.append((bench_name, tinyvec_time / smallvec_time))
|
||||
|
||||
comparisons.sort(key=lambda x: x[1])
|
||||
longest_name = max(len(c[0]) for c in comparisons)
|
||||
for (name, ratio) in comparisons:
|
||||
# Undo the criterion name mangling
|
||||
name = name.replace('_[', '<[')
|
||||
name = name.replace(']___', ']>::')
|
||||
|
||||
name = name.ljust(longest_name)
|
||||
print(f"{name} {ratio:.2f}")
|
||||
53
zeroidc/vendor/tinyvec/gen-array-impls.sh
vendored
Normal file
53
zeroidc/vendor/tinyvec/gen-array-impls.sh
vendored
Normal file
@@ -0,0 +1,53 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
gen_impl() {
|
||||
local len=$1
|
||||
cat <<-END
|
||||
impl<T: Default> Array for [T; $len] {
|
||||
type Item = T;
|
||||
const CAPACITY: usize = $len;
|
||||
|
||||
#[inline(always)]
|
||||
#[must_use]
|
||||
fn as_slice(&self) -> &[T] {
|
||||
&*self
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
#[must_use]
|
||||
fn as_slice_mut(&mut self) -> &mut [T] {
|
||||
&mut *self
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn default() -> Self {
|
||||
[
|
||||
$(for ((i = 0; i < $len; i += 6))
|
||||
do
|
||||
echo -n ' '
|
||||
for ((j = 0; j < 6 && j + i < $len; j++))
|
||||
do
|
||||
echo -n ' T::default(),'
|
||||
done
|
||||
echo
|
||||
done)
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
END
|
||||
}
|
||||
|
||||
cat <<-END
|
||||
// Generated file, to regenerate run
|
||||
// ./gen-array-impls.sh > src/array/generated_impl.rs
|
||||
// from the repo root
|
||||
|
||||
use super::Array;
|
||||
|
||||
$(for ((i = 0; i <= 33; i++)); do gen_impl $i; done)
|
||||
|
||||
$(for ((i = 64; i <= 4096; i *= 2)); do gen_impl $i; done)
|
||||
END
|
||||
|
||||
# vim: noet
|
||||
14
zeroidc/vendor/tinyvec/rustfmt.toml
vendored
Normal file
14
zeroidc/vendor/tinyvec/rustfmt.toml
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
|
||||
# Stable
|
||||
edition = "2018"
|
||||
fn_args_layout = "Compressed"
|
||||
max_width = 80
|
||||
tab_spaces = 2
|
||||
use_field_init_shorthand = true
|
||||
use_try_shorthand = true
|
||||
use_small_heuristics = "Max"
|
||||
|
||||
# Unstable
|
||||
format_code_in_doc_comments = true
|
||||
wrap_comments = true
|
||||
imports_granularity="Crate"
|
||||
303
zeroidc/vendor/tinyvec/src-backup/arrayset.rs
vendored
Normal file
303
zeroidc/vendor/tinyvec/src-backup/arrayset.rs
vendored
Normal file
@@ -0,0 +1,303 @@
|
||||
#![cfg(feature = "experimental_array_set")]
|
||||
|
||||
// This was contributed by user `dhardy`! Big thanks.
|
||||
|
||||
use super::{take, Array};
|
||||
use core::{
|
||||
borrow::Borrow,
|
||||
fmt,
|
||||
mem::swap,
|
||||
ops::{AddAssign, SubAssign},
|
||||
};
|
||||
|
||||
/// Error resulting from attempting to insert into a full array
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
||||
pub struct InsertError;
|
||||
|
||||
// TODO(when std): impl std::error::Error for InsertError {}
|
||||
|
||||
impl fmt::Display for InsertError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "ArraySet: insertion failed")
|
||||
}
|
||||
}
|
||||
|
||||
/// An array-backed set
|
||||
///
|
||||
/// This set supports `O(n)` operations and has a fixed size, thus may fail to
|
||||
/// insert items. The potential advantage is a *really* small size.
|
||||
///
|
||||
/// The set is backed by an array of type `A` and indexed by type `L`.
|
||||
/// The item type must support `Default`.
|
||||
/// Due to restrictions, `L` may be only `u8` or `u16`.
|
||||
#[derive(Clone, Debug, Default)]
|
||||
pub struct ArraySet<A: Array, L> {
|
||||
arr: A,
|
||||
len: L,
|
||||
}
|
||||
|
||||
impl<A: Array + Default, L: From<u8>> ArraySet<A, L> {
|
||||
/// Constructs a new, empty, set
|
||||
#[inline]
|
||||
pub fn new() -> Self {
|
||||
ArraySet { arr: Default::default(), len: 0.into() }
|
||||
}
|
||||
}
|
||||
|
||||
impl<A: Array, L: Copy + Into<usize>> ArraySet<A, L> {
|
||||
/// Constructs a new set from given inputs
|
||||
///
|
||||
/// Panics if `len> arr.len()`.
|
||||
#[inline]
|
||||
pub fn from(arr: A, len: L) -> Self {
|
||||
if len.into() > A::CAPACITY {
|
||||
panic!("ArraySet::from(array, len): len > array.len()");
|
||||
}
|
||||
ArraySet { arr, len }
|
||||
}
|
||||
}
|
||||
|
||||
impl<A: Array, L> ArraySet<A, L>
|
||||
where
|
||||
L: Copy + PartialEq + From<u8> + Into<usize>,
|
||||
{
|
||||
/// Returns the fixed capacity of the set
|
||||
#[inline]
|
||||
pub fn capacity(&self) -> usize {
|
||||
A::CAPACITY
|
||||
}
|
||||
|
||||
/// Returns the number of elements in the set
|
||||
#[inline]
|
||||
pub fn len(&self) -> usize {
|
||||
self.len.into()
|
||||
}
|
||||
|
||||
/// Returns true when the set contains no elements
|
||||
#[inline]
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.len == 0.into()
|
||||
}
|
||||
|
||||
/// Removes all elements
|
||||
#[inline]
|
||||
pub fn clear(&mut self) {
|
||||
self.len = 0.into();
|
||||
}
|
||||
|
||||
/// Iterate over all contents
|
||||
#[inline]
|
||||
pub fn iter(&self) -> Iter<A::Item> {
|
||||
Iter { a: self.arr.as_slice(), i: 0 }
|
||||
}
|
||||
}
|
||||
|
||||
impl<A: Array, L> ArraySet<A, L>
|
||||
where
|
||||
L: Copy + PartialOrd + AddAssign + SubAssign + From<u8> + Into<usize>,
|
||||
{
|
||||
/// Check whether the set contains `elt`
|
||||
#[inline]
|
||||
pub fn contains<Q: Eq + ?Sized>(&self, elt: &Q) -> bool
|
||||
where
|
||||
A::Item: Borrow<Q>,
|
||||
{
|
||||
self.get(elt).is_some()
|
||||
}
|
||||
|
||||
/// Get a reference to a contained item matching `elt`
|
||||
pub fn get<Q: Eq + ?Sized>(&self, elt: &Q) -> Option<&A::Item>
|
||||
where
|
||||
A::Item: Borrow<Q>,
|
||||
{
|
||||
let len: usize = self.len.into();
|
||||
let arr = self.arr.as_slice();
|
||||
for i in 0..len {
|
||||
if arr[i].borrow() == elt {
|
||||
return Some(&arr[i]);
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
/// Remove an item matching `elt`, if any
|
||||
pub fn remove<Q: Eq + ?Sized>(&mut self, elt: &Q) -> Option<A::Item>
|
||||
where
|
||||
A::Item: Borrow<Q>,
|
||||
{
|
||||
let len: usize = self.len.into();
|
||||
let arr = self.arr.as_slice_mut();
|
||||
for i in 0..len {
|
||||
if arr[i].borrow() == elt {
|
||||
let l1 = len - 1;
|
||||
if i < l1 {
|
||||
arr.swap(i, l1);
|
||||
}
|
||||
self.len -= L::from(1);
|
||||
return Some(take(&mut arr[l1]));
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
/// Remove any items for which `f(item) == false`
|
||||
pub fn retain<F>(&mut self, mut f: F)
|
||||
where
|
||||
F: FnMut(&A::Item) -> bool,
|
||||
{
|
||||
let mut len = self.len;
|
||||
let arr = self.arr.as_slice_mut();
|
||||
let mut i = 0;
|
||||
while i < len.into() {
|
||||
if !f(&arr[i]) {
|
||||
len -= L::from(1);
|
||||
if i < len.into() {
|
||||
arr.swap(i, len.into());
|
||||
}
|
||||
} else {
|
||||
i += 1;
|
||||
}
|
||||
}
|
||||
self.len = len;
|
||||
}
|
||||
}
|
||||
|
||||
impl<A: Array, L> ArraySet<A, L>
|
||||
where
|
||||
A::Item: Eq,
|
||||
L: Copy + PartialOrd + AddAssign + SubAssign + From<u8> + Into<usize>,
|
||||
{
|
||||
/// Insert an item
|
||||
///
|
||||
/// Due to the fixed size of the backing array, insertion may fail.
|
||||
#[inline]
|
||||
pub fn insert(&mut self, elt: A::Item) -> Result<bool, InsertError> {
|
||||
if self.contains(&elt) {
|
||||
return Ok(false);
|
||||
}
|
||||
|
||||
let len = self.len.into();
|
||||
let arr = self.arr.as_slice_mut();
|
||||
if len >= arr.len() {
|
||||
return Err(InsertError);
|
||||
}
|
||||
arr[len] = elt;
|
||||
self.len += L::from(1);
|
||||
Ok(true)
|
||||
}
|
||||
|
||||
/* Hits borrow checker
|
||||
pub fn get_or_insert(&mut self, elt: A::Item) -> Result<&A::Item, InsertError> {
|
||||
if let Some(r) = self.get(&elt) {
|
||||
return Ok(r);
|
||||
}
|
||||
self.insert(elt)?;
|
||||
let len: usize = self.len.into();
|
||||
Ok(&self.arr.as_slice()[len - 1])
|
||||
}
|
||||
*/
|
||||
|
||||
/// Replace an item matching `elt` with `elt`, or insert `elt`
|
||||
///
|
||||
/// Returns the replaced item, if any. Fails when there is no matching item
|
||||
/// and the backing array is full, preventing insertion.
|
||||
pub fn replace(
|
||||
&mut self,
|
||||
mut elt: A::Item,
|
||||
) -> Result<Option<A::Item>, InsertError> {
|
||||
let len: usize = self.len.into();
|
||||
let arr = self.arr.as_slice_mut();
|
||||
for i in 0..len {
|
||||
if arr[i] == elt {
|
||||
swap(&mut arr[i], &mut elt);
|
||||
return Ok(Some(elt));
|
||||
}
|
||||
}
|
||||
|
||||
if len >= arr.len() {
|
||||
return Err(InsertError);
|
||||
}
|
||||
arr[len] = elt;
|
||||
self.len += L::from(1);
|
||||
Ok(None)
|
||||
}
|
||||
}
|
||||
|
||||
/// Type returned by [`ArraySet::iter`]
|
||||
pub struct Iter<'a, T> {
|
||||
a: &'a [T],
|
||||
i: usize,
|
||||
}
|
||||
|
||||
impl<'a, T> ExactSizeIterator for Iter<'a, T> {
|
||||
#[inline]
|
||||
fn len(&self) -> usize {
|
||||
self.a.len() - self.i
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, T> Iterator for Iter<'a, T> {
|
||||
type Item = &'a T;
|
||||
|
||||
#[inline]
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
if self.i < self.a.len() {
|
||||
let i = self.i;
|
||||
self.i += 1;
|
||||
Some(&self.a[i])
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn size_hint(&self) -> (usize, Option<usize>) {
|
||||
let len = self.len();
|
||||
(len, Some(len))
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
use core::mem::size_of;
|
||||
|
||||
#[test]
|
||||
fn test_size() {
|
||||
assert_eq!(size_of::<ArraySet<[i8; 7], u8>>(), 8);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test() {
|
||||
let mut set: ArraySet<[i8; 7], u8> = ArraySet::new();
|
||||
assert_eq!(set.capacity(), 7);
|
||||
|
||||
assert_eq!(set.insert(1), Ok(true));
|
||||
assert_eq!(set.insert(5), Ok(true));
|
||||
assert_eq!(set.insert(6), Ok(true));
|
||||
assert_eq!(set.len(), 3);
|
||||
|
||||
assert_eq!(set.insert(5), Ok(false));
|
||||
assert_eq!(set.len(), 3);
|
||||
|
||||
assert_eq!(set.replace(1), Ok(Some(1)));
|
||||
assert_eq!(set.replace(2), Ok(None));
|
||||
assert_eq!(set.len(), 4);
|
||||
|
||||
assert_eq!(set.insert(3), Ok(true));
|
||||
assert_eq!(set.insert(4), Ok(true));
|
||||
assert_eq!(set.insert(7), Ok(true));
|
||||
assert_eq!(set.insert(8), Err(InsertError));
|
||||
assert_eq!(set.len(), 7);
|
||||
|
||||
assert_eq!(set.replace(9), Err(InsertError));
|
||||
|
||||
assert_eq!(set.remove(&3), Some(3));
|
||||
assert_eq!(set.len(), 6);
|
||||
|
||||
set.retain(|x| *x == 3 || *x == 6);
|
||||
assert_eq!(set.len(), 1);
|
||||
assert!(!set.contains(&3));
|
||||
assert!(set.contains(&6));
|
||||
}
|
||||
}
|
||||
48
zeroidc/vendor/tinyvec/src/array.rs
vendored
Normal file
48
zeroidc/vendor/tinyvec/src/array.rs
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
/// A trait for types that are an array.
|
||||
///
|
||||
/// An "array", for our purposes, has the following properties:
|
||||
/// * Owns some number of elements.
|
||||
/// * The element type can be generic, but must implement [`Default`].
|
||||
/// * The capacity is fixed at compile time, based on the implementing type.
|
||||
/// * You can get a shared or mutable slice to the elements.
|
||||
///
|
||||
/// You are generally **not** expected to need to implement this yourself. It is
|
||||
/// already implemented for all the major array lengths (`0..=32` and the powers
|
||||
/// of 2 up to 4,096), or for all array lengths with the feature `rustc_1_55`.
|
||||
///
|
||||
/// **Additional lengths can easily be added upon request.**
|
||||
///
|
||||
/// ## Safety Reminder
|
||||
///
|
||||
/// Just a reminder: this trait is 100% safe, which means that `unsafe` code
|
||||
/// **must not** rely on an instance of this trait being correct.
|
||||
pub trait Array {
|
||||
/// The type of the items in the thing.
|
||||
type Item: Default;
|
||||
|
||||
/// The number of slots in the thing.
|
||||
const CAPACITY: usize;
|
||||
|
||||
/// Gives a shared slice over the whole thing.
|
||||
///
|
||||
/// A correct implementation will return a slice with a length equal to the
|
||||
/// `CAPACITY` value.
|
||||
fn as_slice(&self) -> &[Self::Item];
|
||||
|
||||
/// Gives a unique slice over the whole thing.
|
||||
///
|
||||
/// A correct implementation will return a slice with a length equal to the
|
||||
/// `CAPACITY` value.
|
||||
fn as_slice_mut(&mut self) -> &mut [Self::Item];
|
||||
|
||||
/// Create a default-initialized instance of ourself, similar to the
|
||||
/// [`Default`] trait, but implemented for the same range of sizes as
|
||||
/// [`Array`].
|
||||
fn default() -> Self;
|
||||
}
|
||||
|
||||
#[cfg(feature = "rustc_1_55")]
|
||||
mod const_generic_impl;
|
||||
|
||||
#[cfg(not(feature = "rustc_1_55"))]
|
||||
mod generated_impl;
|
||||
23
zeroidc/vendor/tinyvec/src/array/const_generic_impl.rs
vendored
Normal file
23
zeroidc/vendor/tinyvec/src/array/const_generic_impl.rs
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
use super::Array;
|
||||
|
||||
impl<T: Default, const N: usize> Array for [T; N] {
|
||||
type Item = T;
|
||||
const CAPACITY: usize = N;
|
||||
|
||||
#[inline(always)]
|
||||
#[must_use]
|
||||
fn as_slice(&self) -> &[T] {
|
||||
&*self
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
#[must_use]
|
||||
fn as_slice_mut(&mut self) -> &mut [T] {
|
||||
&mut *self
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn default() -> Self {
|
||||
[(); N].map(|_| Default::default())
|
||||
}
|
||||
}
|
||||
9616
zeroidc/vendor/tinyvec/src/array/generated_impl.rs
vendored
Normal file
9616
zeroidc/vendor/tinyvec/src/array/generated_impl.rs
vendored
Normal file
File diff suppressed because it is too large
Load Diff
1873
zeroidc/vendor/tinyvec/src/arrayvec.rs
vendored
Normal file
1873
zeroidc/vendor/tinyvec/src/arrayvec.rs
vendored
Normal file
File diff suppressed because it is too large
Load Diff
93
zeroidc/vendor/tinyvec/src/arrayvec_drain.rs
vendored
Normal file
93
zeroidc/vendor/tinyvec/src/arrayvec_drain.rs
vendored
Normal file
@@ -0,0 +1,93 @@
|
||||
use super::*;
|
||||
|
||||
use core::{
|
||||
ops::{Bound, RangeBounds},
|
||||
slice,
|
||||
};
|
||||
|
||||
/// Draining iterator for [`ArrayVec`]
|
||||
///
|
||||
/// See [`ArrayVec::drain`](ArrayVec::drain)
|
||||
pub struct ArrayVecDrain<'a, T: 'a + Default> {
|
||||
iter: slice::IterMut<'a, T>,
|
||||
}
|
||||
|
||||
impl<'a, T: 'a + Default> ArrayVecDrain<'a, T> {
|
||||
pub(crate) fn new<A, R>(arr: &'a mut ArrayVec<A>, range: R) -> Self
|
||||
where
|
||||
A: Array<Item = T>,
|
||||
R: RangeBounds<usize>,
|
||||
{
|
||||
let start = match range.start_bound() {
|
||||
Bound::Unbounded => 0,
|
||||
Bound::Included(&n) => n,
|
||||
Bound::Excluded(&n) => n.saturating_add(1),
|
||||
};
|
||||
let end = match range.end_bound() {
|
||||
Bound::Unbounded => arr.len(),
|
||||
Bound::Included(&n) => n.saturating_add(1),
|
||||
Bound::Excluded(&n) => n,
|
||||
};
|
||||
|
||||
assert!(
|
||||
start <= end,
|
||||
"ArrayVec::drain> Illegal range, {} to {}",
|
||||
start,
|
||||
end
|
||||
);
|
||||
assert!(
|
||||
end <= arr.len(),
|
||||
"ArrayVec::drain> Range ends at {}, but length is only {}",
|
||||
end,
|
||||
arr.len()
|
||||
);
|
||||
|
||||
let len = end - start;
|
||||
let to_rotate = &mut arr[start..];
|
||||
to_rotate.rotate_left(len);
|
||||
|
||||
let oldlen = arr.len();
|
||||
let newlen = oldlen - len;
|
||||
arr.set_len(newlen);
|
||||
let slice = &mut arr.data.as_slice_mut()[newlen..oldlen];
|
||||
let iter = slice.iter_mut();
|
||||
Self { iter }
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, T: 'a + Default> DoubleEndedIterator for ArrayVecDrain<'a, T> {
|
||||
fn next_back(&mut self) -> Option<Self::Item> {
|
||||
self.iter.next_back().map(take)
|
||||
}
|
||||
|
||||
#[cfg(feature = "rustc_1_40")]
|
||||
fn nth_back(&mut self, n: usize) -> Option<Self::Item> {
|
||||
self.iter.nth_back(n).map(take)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, T: 'a + Default> Iterator for ArrayVecDrain<'a, T> {
|
||||
type Item = T;
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
self.iter.next().map(take)
|
||||
}
|
||||
fn size_hint(&self) -> (usize, Option<usize>) {
|
||||
self.iter.size_hint()
|
||||
}
|
||||
fn nth(&mut self, n: usize) -> Option<Self::Item> {
|
||||
self.iter.nth(n).map(take)
|
||||
}
|
||||
fn last(self) -> Option<Self::Item> {
|
||||
self.iter.last().map(take)
|
||||
}
|
||||
fn for_each<F>(self, f: F)
|
||||
where
|
||||
F: FnMut(Self::Item),
|
||||
{
|
||||
self.iter.map(take).for_each(f)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, T: 'a + Default> FusedIterator for ArrayVecDrain<'a, T> {}
|
||||
impl<'a, T: 'a + Default> ExactSizeIterator for ArrayVecDrain<'a, T> {}
|
||||
/* No need to impl Drop! */
|
||||
107
zeroidc/vendor/tinyvec/src/lib.rs
vendored
Normal file
107
zeroidc/vendor/tinyvec/src/lib.rs
vendored
Normal file
@@ -0,0 +1,107 @@
|
||||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
#![forbid(unsafe_code)]
|
||||
#![cfg_attr(
|
||||
feature = "nightly_slice_partition_dedup",
|
||||
feature(slice_partition_dedup)
|
||||
)]
|
||||
#![cfg_attr(docs_rs, feature(doc_cfg))]
|
||||
#![warn(clippy::missing_inline_in_public_items)]
|
||||
#![warn(clippy::must_use_candidate)]
|
||||
#![warn(missing_docs)]
|
||||
|
||||
//! `tinyvec` provides 100% safe vec-like data structures.
|
||||
//!
|
||||
//! ## Provided Types
|
||||
//! With no features enabled, this crate provides the [`ArrayVec`] type, which
|
||||
//! is an array-backed storage. You can push values into the array and pop them
|
||||
//! out of the array and so on. If the array is made to overflow it will panic.
|
||||
//!
|
||||
//! Similarly, there is also a [`SliceVec`] type available, which is a vec-like
|
||||
//! that's backed by a slice you provide. You can add and remove elements, but
|
||||
//! if you overflow the slice it will panic.
|
||||
//!
|
||||
//! With the `alloc` feature enabled, the crate also has a [`TinyVec`] type.
|
||||
//! This is an enum type which is either an `Inline(ArrayVec)` or a `Heap(Vec)`.
|
||||
//! If a `TinyVec` is `Inline` and would overflow it automatically transitions
|
||||
//! itself into being `Heap` mode instead of a panic.
|
||||
//!
|
||||
//! All of this is done with no `unsafe` code within the crate. Technically the
|
||||
//! `Vec` type from the standard library uses `unsafe` internally, but *this
|
||||
//! crate* introduces no new `unsafe` code into your project.
|
||||
//!
|
||||
//! The limitation is that the element type of a vec from this crate must
|
||||
//! support the [`Default`] trait. This means that this crate isn't suitable for
|
||||
//! all situations, but a very surprising number of types do support `Default`.
|
||||
//!
|
||||
//! ## Other Features
|
||||
//! * `grab_spare_slice` lets you get access to the "inactive" portions of an
|
||||
//! ArrayVec.
|
||||
//! * `rustc_1_40` makes the crate assume a minimum rust version of `1.40.0`,
|
||||
//! which allows some better internal optimizations.
|
||||
//! * `serde` provides a `Serialize` and `Deserialize` implementation for
|
||||
//! [`TinyVec`] and [`ArrayVec`] types, provided the inner item also has an
|
||||
//! implementation.
|
||||
//!
|
||||
//! ## API
|
||||
//! The general goal of the crate is that, as much as possible, the vecs here
|
||||
//! should be a "drop in" replacement for the standard library `Vec` type. We
|
||||
//! strive to provide all of the `Vec` methods with the same names and
|
||||
//! signatures. The exception is that the element type of some methods will have
|
||||
//! a `Default` bound that's not part of the normal `Vec` type.
|
||||
//!
|
||||
//! The vecs here also have a few additional methods that aren't on the `Vec`
|
||||
//! type. In this case, the names tend to be fairly long so that they are
|
||||
//! unlikely to clash with any future methods added to `Vec`.
|
||||
//!
|
||||
//! ## Stability
|
||||
//! * The `1.0` series of the crate works with Rustc `1.34.0` or later, though
|
||||
//! you still need to have Rustc `1.36.0` to use the `alloc` feature.
|
||||
//! * The `2.0` version of the crate is planned for some time after the
|
||||
//! `min_const_generics` stuff becomes stable. This would greatly raise the
|
||||
//! minimum rust version and also allow us to totally eliminate the need for
|
||||
//! the `Array` trait. The actual usage of the crate is not expected to break
|
||||
//! significantly in this transition.
|
||||
|
||||
#[allow(unused_imports)]
|
||||
use core::{
|
||||
borrow::{Borrow, BorrowMut},
|
||||
cmp::PartialEq,
|
||||
convert::AsMut,
|
||||
default::Default,
|
||||
fmt::{
|
||||
Binary, Debug, Display, Formatter, LowerExp, LowerHex, Octal, Pointer,
|
||||
UpperExp, UpperHex,
|
||||
},
|
||||
hash::{Hash, Hasher},
|
||||
iter::{Extend, FromIterator, FusedIterator, IntoIterator, Iterator},
|
||||
mem::{needs_drop, replace},
|
||||
ops::{Deref, DerefMut, Index, IndexMut, RangeBounds},
|
||||
slice::SliceIndex,
|
||||
};
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
#[doc(hidden)] // re-export for macros
|
||||
pub extern crate alloc;
|
||||
|
||||
mod array;
|
||||
pub use array::*;
|
||||
|
||||
mod arrayvec;
|
||||
pub use arrayvec::*;
|
||||
|
||||
mod arrayvec_drain;
|
||||
pub use arrayvec_drain::*;
|
||||
|
||||
mod slicevec;
|
||||
pub use slicevec::*;
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
mod tinyvec;
|
||||
#[cfg(feature = "alloc")]
|
||||
pub use crate::tinyvec::*;
|
||||
|
||||
// TODO MSRV(1.40.0): Just call the normal `core::mem::take`
|
||||
#[inline(always)]
|
||||
fn take<T: Default>(from: &mut T) -> T {
|
||||
replace(from, T::default())
|
||||
}
|
||||
1080
zeroidc/vendor/tinyvec/src/slicevec.rs
vendored
Normal file
1080
zeroidc/vendor/tinyvec/src/slicevec.rs
vendored
Normal file
File diff suppressed because it is too large
Load Diff
1740
zeroidc/vendor/tinyvec/src/tinyvec.rs
vendored
Normal file
1740
zeroidc/vendor/tinyvec/src/tinyvec.rs
vendored
Normal file
File diff suppressed because it is too large
Load Diff
477
zeroidc/vendor/tinyvec/tests/arrayvec.rs
vendored
Normal file
477
zeroidc/vendor/tinyvec/tests/arrayvec.rs
vendored
Normal file
@@ -0,0 +1,477 @@
|
||||
#![allow(bad_style)]
|
||||
|
||||
#[cfg(feature = "serde")]
|
||||
use serde_test::{assert_tokens, Token};
|
||||
use std::iter::FromIterator;
|
||||
use tinyvec::*;
|
||||
|
||||
#[test]
|
||||
fn test_a_vec() {
|
||||
let mut expected: ArrayVec<[i32; 4]> = Default::default();
|
||||
expected.push(1);
|
||||
expected.push(2);
|
||||
expected.push(3);
|
||||
|
||||
let actual = array_vec!(1, 2, 3);
|
||||
|
||||
assert_eq!(expected, actual);
|
||||
|
||||
assert_eq!(array_vec![0u8; 4], array_vec!(0u8, 0u8, 0u8, 0u8));
|
||||
assert_eq!(array_vec![0u8; 4], array_vec!([u8; 4] => 0, 0, 0, 0));
|
||||
assert_eq!(array_vec![0; 4], array_vec!(0, 0, 0, 0));
|
||||
assert_eq!(array_vec![0; 4], array_vec!([u8; 4] => 0, 0, 0, 0));
|
||||
|
||||
let expected2 = array_vec![1.1; 3];
|
||||
let actual2 = array_vec!([f32; 3] => 1.1, 1.1, 1.1);
|
||||
assert_eq!(expected2, actual2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ArrayVec_push_pop() {
|
||||
let mut av: ArrayVec<[i32; 4]> = Default::default();
|
||||
assert_eq!(av.len(), 0);
|
||||
assert_eq!(av.pop(), None);
|
||||
|
||||
av.push(10_i32);
|
||||
assert_eq!(av.len(), 1);
|
||||
assert_eq!(av[0], 10);
|
||||
assert_eq!(av.pop(), Some(10));
|
||||
assert_eq!(av.len(), 0);
|
||||
assert_eq!(av.pop(), None);
|
||||
|
||||
av.push(10);
|
||||
av.push(11);
|
||||
av.push(12);
|
||||
av.push(13);
|
||||
assert_eq!(av[0], 10);
|
||||
assert_eq!(av[1], 11);
|
||||
assert_eq!(av[2], 12);
|
||||
assert_eq!(av[3], 13);
|
||||
assert_eq!(av.len(), 4);
|
||||
assert_eq!(av.pop(), Some(13));
|
||||
assert_eq!(av.len(), 3);
|
||||
assert_eq!(av.pop(), Some(12));
|
||||
assert_eq!(av.len(), 2);
|
||||
assert_eq!(av.pop(), Some(11));
|
||||
assert_eq!(av.len(), 1);
|
||||
assert_eq!(av.pop(), Some(10));
|
||||
assert_eq!(av.len(), 0);
|
||||
assert_eq!(av.pop(), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn ArrayVec_push_overflow() {
|
||||
let mut av: ArrayVec<[i32; 0]> = Default::default();
|
||||
av.push(7);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ArrayVec_formatting() {
|
||||
// check that we get the comma placement correct
|
||||
|
||||
let mut av: ArrayVec<[i32; 4]> = Default::default();
|
||||
assert_eq!(format!("{:?}", av), "[]");
|
||||
av.push(10);
|
||||
assert_eq!(format!("{:?}", av), "[10]");
|
||||
av.push(11);
|
||||
assert_eq!(format!("{:?}", av), "[10, 11]");
|
||||
av.push(12);
|
||||
assert_eq!(format!("{:?}", av), "[10, 11, 12]");
|
||||
|
||||
// below here just asserts that the impls exist.
|
||||
|
||||
//
|
||||
let av: ArrayVec<[i32; 4]> = Default::default();
|
||||
assert_eq!(format!("{:b}", av), "[]");
|
||||
assert_eq!(format!("{:o}", av), "[]");
|
||||
assert_eq!(format!("{:x}", av), "[]");
|
||||
assert_eq!(format!("{:X}", av), "[]");
|
||||
assert_eq!(format!("{}", av), "[]");
|
||||
//
|
||||
let av: ArrayVec<[f32; 4]> = Default::default();
|
||||
assert_eq!(format!("{:e}", av), "[]");
|
||||
assert_eq!(format!("{:E}", av), "[]");
|
||||
//
|
||||
let av: ArrayVec<[&'static str; 4]> = Default::default();
|
||||
assert_eq!(format!("{:p}", av), "[]");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ArrayVec_iteration() {
|
||||
let av = array_vec!([i32; 4] => 10, 11, 12, 13);
|
||||
|
||||
let mut i = av.into_iter();
|
||||
assert_eq!(i.next(), Some(10));
|
||||
assert_eq!(i.next(), Some(11));
|
||||
assert_eq!(i.next(), Some(12));
|
||||
assert_eq!(i.next(), Some(13));
|
||||
assert_eq!(i.next(), None);
|
||||
|
||||
let av = array_vec!([i32; 4] => 10, 11, 12, 13);
|
||||
|
||||
let mut av2: ArrayVec<[i32; 4]> = av.clone().into_iter().collect();
|
||||
assert_eq!(av, av2);
|
||||
|
||||
// IntoIterator for &mut ArrayVec
|
||||
for x in &mut av2 {
|
||||
*x = -*x;
|
||||
}
|
||||
|
||||
// IntoIterator for &ArrayVec
|
||||
assert!(av.iter().zip(&av2).all(|(&a, &b)| a == -b));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ArrayVec_append() {
|
||||
let mut av = array_vec!([i32; 8] => 1, 2, 3);
|
||||
let mut av2 = array_vec!([i32; 8] => 4, 5, 6);
|
||||
//
|
||||
av.append(&mut av2);
|
||||
assert_eq!(av.as_slice(), &[1_i32, 2, 3, 4, 5, 6]);
|
||||
assert_eq!(av2.as_slice(), &[]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ArrayVec_remove() {
|
||||
let mut av: ArrayVec<[i32; 10]> = Default::default();
|
||||
av.push(1);
|
||||
av.push(2);
|
||||
av.push(3);
|
||||
assert_eq!(av.remove(1), 2);
|
||||
assert_eq!(&av[..], &[1, 3][..]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn ArrayVec_remove_invalid() {
|
||||
let mut av: ArrayVec<[i32; 1]> = Default::default();
|
||||
av.push(1);
|
||||
av.remove(1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ArrayVec_swap_remove() {
|
||||
let mut av: ArrayVec<[i32; 10]> = Default::default();
|
||||
av.push(1);
|
||||
av.push(2);
|
||||
av.push(3);
|
||||
av.push(4);
|
||||
assert_eq!(av.swap_remove(3), 4);
|
||||
assert_eq!(&av[..], &[1, 2, 3][..]);
|
||||
assert_eq!(av.swap_remove(0), 1);
|
||||
assert_eq!(&av[..], &[3, 2][..]);
|
||||
assert_eq!(av.swap_remove(0), 3);
|
||||
assert_eq!(&av[..], &[2][..]);
|
||||
assert_eq!(av.swap_remove(0), 2);
|
||||
assert_eq!(&av[..], &[][..]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ArrayVec_drain() {
|
||||
let mut av: ArrayVec<[i32; 10]> = Default::default();
|
||||
av.push(1);
|
||||
av.push(2);
|
||||
av.push(3);
|
||||
|
||||
assert_eq!(Vec::from_iter(av.clone().drain(..)), vec![1, 2, 3]);
|
||||
|
||||
assert_eq!(Vec::from_iter(av.clone().drain(..2)), vec![1, 2]);
|
||||
assert_eq!(Vec::from_iter(av.clone().drain(..3)), vec![1, 2, 3]);
|
||||
|
||||
assert_eq!(Vec::from_iter(av.clone().drain(..=1)), vec![1, 2]);
|
||||
assert_eq!(Vec::from_iter(av.clone().drain(..=2)), vec![1, 2, 3]);
|
||||
|
||||
assert_eq!(Vec::from_iter(av.clone().drain(0..)), vec![1, 2, 3]);
|
||||
assert_eq!(Vec::from_iter(av.clone().drain(1..)), vec![2, 3]);
|
||||
|
||||
assert_eq!(Vec::from_iter(av.clone().drain(0..2)), vec![1, 2]);
|
||||
assert_eq!(Vec::from_iter(av.clone().drain(0..3)), vec![1, 2, 3]);
|
||||
assert_eq!(Vec::from_iter(av.clone().drain(1..2)), vec![2]);
|
||||
assert_eq!(Vec::from_iter(av.clone().drain(1..3)), vec![2, 3]);
|
||||
|
||||
assert_eq!(Vec::from_iter(av.clone().drain(0..=1)), vec![1, 2]);
|
||||
assert_eq!(Vec::from_iter(av.clone().drain(0..=2)), vec![1, 2, 3]);
|
||||
assert_eq!(Vec::from_iter(av.clone().drain(1..=1)), vec![2]);
|
||||
assert_eq!(Vec::from_iter(av.clone().drain(1..=2)), vec![2, 3]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ArrayVec_splice() {
|
||||
let mut av: ArrayVec<[i32; 10]> = Default::default();
|
||||
av.push(1);
|
||||
av.push(2);
|
||||
av.push(3);
|
||||
|
||||
// splice returns the same things as drain
|
||||
assert_eq!(Vec::from_iter(av.clone().splice(.., None)), vec![1, 2, 3]);
|
||||
|
||||
assert_eq!(Vec::from_iter(av.clone().splice(..2, None)), vec![1, 2]);
|
||||
assert_eq!(Vec::from_iter(av.clone().splice(..3, None)), vec![1, 2, 3]);
|
||||
|
||||
assert_eq!(Vec::from_iter(av.clone().splice(..=1, None)), vec![1, 2]);
|
||||
assert_eq!(Vec::from_iter(av.clone().splice(..=2, None)), vec![1, 2, 3]);
|
||||
|
||||
assert_eq!(Vec::from_iter(av.clone().splice(0.., None)), vec![1, 2, 3]);
|
||||
assert_eq!(Vec::from_iter(av.clone().splice(1.., None)), vec![2, 3]);
|
||||
|
||||
assert_eq!(Vec::from_iter(av.clone().splice(0..2, None)), vec![1, 2]);
|
||||
assert_eq!(Vec::from_iter(av.clone().splice(0..3, None)), vec![1, 2, 3]);
|
||||
assert_eq!(Vec::from_iter(av.clone().splice(1..2, None)), vec![2]);
|
||||
assert_eq!(Vec::from_iter(av.clone().splice(1..3, None)), vec![2, 3]);
|
||||
|
||||
assert_eq!(Vec::from_iter(av.clone().splice(0..=1, None)), vec![1, 2]);
|
||||
assert_eq!(Vec::from_iter(av.clone().splice(0..=2, None)), vec![1, 2, 3]);
|
||||
assert_eq!(Vec::from_iter(av.clone().splice(1..=1, None)), vec![2]);
|
||||
assert_eq!(Vec::from_iter(av.clone().splice(1..=2, None)), vec![2, 3]);
|
||||
|
||||
// splice removes the same things as drain
|
||||
let mut av2 = av.clone();
|
||||
av2.splice(.., None);
|
||||
assert_eq!(av2, array_vec![]);
|
||||
|
||||
let mut av2 = av.clone();
|
||||
av2.splice(..2, None);
|
||||
assert_eq!(av2, array_vec![3]);
|
||||
|
||||
let mut av2 = av.clone();
|
||||
av2.splice(..3, None);
|
||||
assert_eq!(av2, array_vec![]);
|
||||
|
||||
let mut av2 = av.clone();
|
||||
av2.splice(..=1, None);
|
||||
assert_eq!(av2, array_vec![3]);
|
||||
let mut av2 = av.clone();
|
||||
av2.splice(..=2, None);
|
||||
assert_eq!(av2, array_vec![]);
|
||||
|
||||
let mut av2 = av.clone();
|
||||
av2.splice(0.., None);
|
||||
assert_eq!(av2, array_vec![]);
|
||||
let mut av2 = av.clone();
|
||||
av2.splice(1.., None);
|
||||
assert_eq!(av2, array_vec![1]);
|
||||
|
||||
let mut av2 = av.clone();
|
||||
av2.splice(0..2, None);
|
||||
assert_eq!(av2, array_vec![3]);
|
||||
|
||||
let mut av2 = av.clone();
|
||||
av2.splice(0..3, None);
|
||||
assert_eq!(av2, array_vec![]);
|
||||
let mut av2 = av.clone();
|
||||
av2.splice(1..2, None);
|
||||
assert_eq!(av2, array_vec![1, 3]);
|
||||
|
||||
let mut av2 = av.clone();
|
||||
av2.splice(1..3, None);
|
||||
assert_eq!(av2, array_vec![1]);
|
||||
|
||||
let mut av2 = av.clone();
|
||||
av2.splice(0..=1, None);
|
||||
assert_eq!(av2, array_vec![3]);
|
||||
|
||||
let mut av2 = av.clone();
|
||||
av2.splice(0..=2, None);
|
||||
assert_eq!(av2, array_vec![]);
|
||||
|
||||
let mut av2 = av.clone();
|
||||
av2.splice(1..=1, None);
|
||||
assert_eq!(av2, array_vec![1, 3]);
|
||||
|
||||
let mut av2 = av.clone();
|
||||
av2.splice(1..=2, None);
|
||||
assert_eq!(av2, array_vec![1]);
|
||||
|
||||
// splice adds the elements correctly
|
||||
let mut av2 = av.clone();
|
||||
av2.splice(.., 4..=6);
|
||||
assert_eq!(av2, array_vec![4, 5, 6]);
|
||||
|
||||
let mut av2 = av.clone();
|
||||
av2.splice(..2, 4..=6);
|
||||
assert_eq!(av2, array_vec![4, 5, 6, 3]);
|
||||
|
||||
let mut av2 = av.clone();
|
||||
av2.splice(..3, 4..=6);
|
||||
assert_eq!(av2, array_vec![4, 5, 6]);
|
||||
|
||||
let mut av2 = av.clone();
|
||||
av2.splice(..=1, 4..=6);
|
||||
assert_eq!(av2, array_vec![4, 5, 6, 3]);
|
||||
|
||||
let mut av2 = av.clone();
|
||||
av2.splice(..=2, 4..=6);
|
||||
assert_eq!(av2, array_vec![4, 5, 6]);
|
||||
|
||||
let mut av2 = av.clone();
|
||||
av2.splice(0.., 4..=6);
|
||||
assert_eq!(av2, array_vec![4, 5, 6]);
|
||||
|
||||
let mut av2 = av.clone();
|
||||
av2.splice(1.., 4..=6);
|
||||
assert_eq!(av2, array_vec![1, 4, 5, 6]);
|
||||
|
||||
let mut av2 = av.clone();
|
||||
av2.splice(0..2, 4..=6);
|
||||
assert_eq!(av2, array_vec![4, 5, 6, 3]);
|
||||
|
||||
let mut av2 = av.clone();
|
||||
av2.splice(0..3, 4..=6);
|
||||
assert_eq!(av2, array_vec![4, 5, 6]);
|
||||
|
||||
let mut av2 = av.clone();
|
||||
av2.splice(1..2, 4..=6);
|
||||
assert_eq!(av2, array_vec![1, 4, 5, 6, 3]);
|
||||
|
||||
let mut av2 = av.clone();
|
||||
av2.splice(1..3, 4..=6);
|
||||
assert_eq!(av2, array_vec![1, 4, 5, 6]);
|
||||
|
||||
let mut av2 = av.clone();
|
||||
av2.splice(0..=1, 4..=6);
|
||||
assert_eq!(av2, array_vec![4, 5, 6, 3]);
|
||||
|
||||
let mut av2 = av.clone();
|
||||
av2.splice(0..=2, 4..=6);
|
||||
assert_eq!(av2, array_vec![4, 5, 6]);
|
||||
|
||||
let mut av2 = av.clone();
|
||||
av2.splice(1..=1, 4..=6);
|
||||
assert_eq!(av2, array_vec![1, 4, 5, 6, 3]);
|
||||
|
||||
let mut av2 = av.clone();
|
||||
av2.splice(1..=2, 4..=6);
|
||||
assert_eq!(av2, array_vec![1, 4, 5, 6]);
|
||||
|
||||
// splice adds the elements correctly when the replacement is smaller
|
||||
let mut av2 = av.clone();
|
||||
av2.splice(.., Some(4));
|
||||
assert_eq!(av2, array_vec![4]);
|
||||
|
||||
let mut av2 = av.clone();
|
||||
av2.splice(..2, Some(4));
|
||||
assert_eq!(av2, array_vec![4, 3]);
|
||||
|
||||
let mut av2 = av.clone();
|
||||
av2.splice(1.., Some(4));
|
||||
assert_eq!(av2, array_vec![1, 4]);
|
||||
|
||||
let mut av2 = av.clone();
|
||||
av2.splice(1..=1, Some(4));
|
||||
assert_eq!(av2, array_vec![1, 4, 3]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn iter_last_nth() {
|
||||
let mut av: ArrayVec<[i32; 10]> = Default::default();
|
||||
av.push(1);
|
||||
av.push(2);
|
||||
av.push(3);
|
||||
av.push(4);
|
||||
assert_eq!(av.len(), 4);
|
||||
let mut iter = av.into_iter();
|
||||
assert_eq!(iter.next(), Some(1));
|
||||
assert_eq!(iter.next(), Some(2));
|
||||
assert_eq!(iter.next(), Some(3));
|
||||
assert_eq!(iter.next(), Some(4));
|
||||
assert_eq!(iter.next(), None);
|
||||
assert_eq!(iter.last(), None);
|
||||
|
||||
let mut av: ArrayVec<[i32; 10]> = Default::default();
|
||||
av.push(1);
|
||||
av.push(2);
|
||||
av.push(3);
|
||||
|
||||
assert_eq!(av.into_iter().nth(0), Some(1));
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "rustc_1_40")]
|
||||
fn reviter() {
|
||||
let mut av: ArrayVec<[i32; 10]> = Default::default();
|
||||
av.push(1);
|
||||
av.push(2);
|
||||
av.push(3);
|
||||
av.push(4);
|
||||
|
||||
let mut iter = av.into_iter();
|
||||
|
||||
assert_eq!(iter.next(), Some(1));
|
||||
assert_eq!(iter.next_back(), Some(4));
|
||||
assert_eq!(iter.next(), Some(2));
|
||||
assert_eq!(iter.next_back(), Some(3));
|
||||
assert_eq!(iter.next(), None);
|
||||
assert_eq!(iter.next_back(), None);
|
||||
|
||||
let mut av: ArrayVec<[i32; 32]> = Default::default();
|
||||
av.extend(0..32);
|
||||
|
||||
let mut iter = av.into_iter();
|
||||
|
||||
assert_eq!(iter.nth_back(0), Some(31));
|
||||
assert_eq!(iter.nth_back(2), Some(28));
|
||||
assert_eq!(iter.nth_back(0), Some(27));
|
||||
assert_eq!(iter.nth_back(99), None);
|
||||
assert_eq!(iter.nth_back(99), None);
|
||||
}
|
||||
|
||||
#[cfg(feature = "serde")]
|
||||
#[test]
|
||||
fn ArrayVec_ser_de_empty() {
|
||||
let tv: ArrayVec<[i32; 0]> = Default::default();
|
||||
|
||||
assert_tokens(&tv, &[Token::Seq { len: Some(0) }, Token::SeqEnd]);
|
||||
}
|
||||
|
||||
#[cfg(feature = "serde")]
|
||||
#[test]
|
||||
fn ArrayVec_ser_de() {
|
||||
let mut tv: ArrayVec<[i32; 4]> = Default::default();
|
||||
tv.push(1);
|
||||
tv.push(2);
|
||||
tv.push(3);
|
||||
tv.push(4);
|
||||
|
||||
assert_tokens(
|
||||
&tv,
|
||||
&[
|
||||
Token::Seq { len: Some(4) },
|
||||
Token::I32(1),
|
||||
Token::I32(2),
|
||||
Token::I32(3),
|
||||
Token::I32(4),
|
||||
Token::SeqEnd,
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ArrayVec_try_from_slice() {
|
||||
use std::convert::TryFrom;
|
||||
|
||||
let nums = [1, 2, 3, 4];
|
||||
|
||||
let empty: Result<ArrayVec<[i32; 2]>, _> = ArrayVec::try_from(&nums[..0]);
|
||||
assert!(empty.is_ok());
|
||||
assert_eq!(empty.unwrap().as_slice(), &[]);
|
||||
|
||||
let fits: Result<ArrayVec<[i32; 2]>, _> = ArrayVec::try_from(&nums[..2]);
|
||||
assert!(fits.is_ok());
|
||||
assert_eq!(fits.unwrap().as_slice(), &[1, 2]);
|
||||
|
||||
let doesnt_fit: Result<ArrayVec<[i32; 2]>, _> =
|
||||
ArrayVec::try_from(&nums[..4]);
|
||||
assert!(doesnt_fit.is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ArrayVec_pretty_debug() {
|
||||
let arr: [i32; 3] = [1, 2, 3];
|
||||
let expect = format!("{:#?}", arr);
|
||||
|
||||
let arr: ArrayVec<[i32; 3]> = array_vec![1, 2, 3];
|
||||
let got = format!("{:#?}", arr);
|
||||
|
||||
assert_eq!(got, expect);
|
||||
}
|
||||
468
zeroidc/vendor/tinyvec/tests/tinyvec.rs
vendored
Normal file
468
zeroidc/vendor/tinyvec/tests/tinyvec.rs
vendored
Normal file
@@ -0,0 +1,468 @@
|
||||
#![cfg(feature = "alloc")]
|
||||
#![allow(bad_style)]
|
||||
#![allow(clippy::redundant_clone)]
|
||||
|
||||
#[cfg(feature = "serde")]
|
||||
use serde_test::{assert_tokens, Token};
|
||||
use std::iter::FromIterator;
|
||||
use tinyvec::*;
|
||||
|
||||
#[test]
|
||||
fn TinyVec_swap_remove() {
|
||||
let mut tv: TinyVec<[i32; 10]> = Default::default();
|
||||
tv.push(1);
|
||||
tv.push(2);
|
||||
tv.push(3);
|
||||
tv.push(4);
|
||||
assert_eq!(tv.swap_remove(3), 4);
|
||||
assert_eq!(&tv[..], &[1, 2, 3][..]);
|
||||
assert_eq!(tv.swap_remove(0), 1);
|
||||
assert_eq!(&tv[..], &[3, 2][..]);
|
||||
assert_eq!(tv.swap_remove(0), 3);
|
||||
assert_eq!(&tv[..], &[2][..]);
|
||||
assert_eq!(tv.swap_remove(0), 2);
|
||||
assert_eq!(&tv[..], &[][..]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn TinyVec_capacity() {
|
||||
let mut tv: TinyVec<[i32; 1]> = Default::default();
|
||||
assert_eq!(tv.capacity(), 1);
|
||||
tv.move_to_the_heap();
|
||||
tv.extend_from_slice(&[1, 2, 3, 4]);
|
||||
assert_eq!(tv.capacity(), 4);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn TinyVec_drain() {
|
||||
let mut tv: TinyVec<[i32; 10]> = Default::default();
|
||||
tv.push(1);
|
||||
tv.push(2);
|
||||
tv.push(3);
|
||||
|
||||
assert_eq!(Vec::from_iter(tv.clone().drain(..)), vec![1, 2, 3]);
|
||||
|
||||
assert_eq!(Vec::from_iter(tv.clone().drain(..2)), vec![1, 2]);
|
||||
assert_eq!(Vec::from_iter(tv.clone().drain(..3)), vec![1, 2, 3]);
|
||||
|
||||
assert_eq!(Vec::from_iter(tv.clone().drain(..=1)), vec![1, 2]);
|
||||
assert_eq!(Vec::from_iter(tv.clone().drain(..=2)), vec![1, 2, 3]);
|
||||
|
||||
assert_eq!(Vec::from_iter(tv.clone().drain(0..)), vec![1, 2, 3]);
|
||||
assert_eq!(Vec::from_iter(tv.clone().drain(1..)), vec![2, 3]);
|
||||
|
||||
assert_eq!(Vec::from_iter(tv.clone().drain(0..2)), vec![1, 2]);
|
||||
assert_eq!(Vec::from_iter(tv.clone().drain(0..3)), vec![1, 2, 3]);
|
||||
assert_eq!(Vec::from_iter(tv.clone().drain(1..2)), vec![2]);
|
||||
assert_eq!(Vec::from_iter(tv.clone().drain(1..3)), vec![2, 3]);
|
||||
|
||||
assert_eq!(Vec::from_iter(tv.clone().drain(0..=1)), vec![1, 2]);
|
||||
assert_eq!(Vec::from_iter(tv.clone().drain(0..=2)), vec![1, 2, 3]);
|
||||
assert_eq!(Vec::from_iter(tv.clone().drain(1..=1)), vec![2]);
|
||||
assert_eq!(Vec::from_iter(tv.clone().drain(1..=2)), vec![2, 3]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn TinyVec_splice() {
|
||||
let mut tv: TinyVec<[i32; 10]> = Default::default();
|
||||
tv.push(1);
|
||||
tv.push(2);
|
||||
tv.push(3);
|
||||
|
||||
// splice returns the same things as drain
|
||||
assert_eq!(Vec::from_iter(tv.clone().splice(.., None)), vec![1, 2, 3]);
|
||||
|
||||
assert_eq!(Vec::from_iter(tv.clone().splice(..2, None)), vec![1, 2]);
|
||||
assert_eq!(Vec::from_iter(tv.clone().splice(..3, None)), vec![1, 2, 3]);
|
||||
|
||||
assert_eq!(Vec::from_iter(tv.clone().splice(..=1, None)), vec![1, 2]);
|
||||
assert_eq!(Vec::from_iter(tv.clone().splice(..=2, None)), vec![1, 2, 3]);
|
||||
|
||||
assert_eq!(Vec::from_iter(tv.clone().splice(0.., None)), vec![1, 2, 3]);
|
||||
assert_eq!(Vec::from_iter(tv.clone().splice(1.., None)), vec![2, 3]);
|
||||
|
||||
assert_eq!(Vec::from_iter(tv.clone().splice(0..2, None)), vec![1, 2]);
|
||||
assert_eq!(Vec::from_iter(tv.clone().splice(0..3, None)), vec![1, 2, 3]);
|
||||
assert_eq!(Vec::from_iter(tv.clone().splice(1..2, None)), vec![2]);
|
||||
assert_eq!(Vec::from_iter(tv.clone().splice(1..3, None)), vec![2, 3]);
|
||||
|
||||
assert_eq!(Vec::from_iter(tv.clone().splice(0..=1, None)), vec![1, 2]);
|
||||
assert_eq!(Vec::from_iter(tv.clone().splice(0..=2, None)), vec![1, 2, 3]);
|
||||
assert_eq!(Vec::from_iter(tv.clone().splice(1..=1, None)), vec![2]);
|
||||
assert_eq!(Vec::from_iter(tv.clone().splice(1..=2, None)), vec![2, 3]);
|
||||
|
||||
// splice removes the same things as drain
|
||||
let mut tv2 = tv.clone();
|
||||
tv2.splice(.., None);
|
||||
assert_eq!(tv2, tiny_vec![]);
|
||||
|
||||
let mut tv2 = tv.clone();
|
||||
tv2.splice(..2, None);
|
||||
assert_eq!(tv2, tiny_vec![3]);
|
||||
|
||||
let mut tv2 = tv.clone();
|
||||
tv2.splice(..3, None);
|
||||
assert_eq!(tv2, tiny_vec![]);
|
||||
|
||||
let mut tv2 = tv.clone();
|
||||
tv2.splice(..=1, None);
|
||||
assert_eq!(tv2, tiny_vec![3]);
|
||||
let mut tv2 = tv.clone();
|
||||
tv2.splice(..=2, None);
|
||||
assert_eq!(tv2, tiny_vec![]);
|
||||
|
||||
let mut tv2 = tv.clone();
|
||||
tv2.splice(0.., None);
|
||||
assert_eq!(tv2, tiny_vec![]);
|
||||
let mut tv2 = tv.clone();
|
||||
tv2.splice(1.., None);
|
||||
assert_eq!(tv2, tiny_vec![1]);
|
||||
|
||||
let mut tv2 = tv.clone();
|
||||
tv2.splice(0..2, None);
|
||||
assert_eq!(tv2, tiny_vec![3]);
|
||||
|
||||
let mut tv2 = tv.clone();
|
||||
tv2.splice(0..3, None);
|
||||
assert_eq!(tv2, tiny_vec![]);
|
||||
let mut tv2 = tv.clone();
|
||||
tv2.splice(1..2, None);
|
||||
assert_eq!(tv2, tiny_vec![1, 3]);
|
||||
|
||||
let mut tv2 = tv.clone();
|
||||
tv2.splice(1..3, None);
|
||||
assert_eq!(tv2, tiny_vec![1]);
|
||||
|
||||
let mut tv2 = tv.clone();
|
||||
tv2.splice(0..=1, None);
|
||||
assert_eq!(tv2, tiny_vec![3]);
|
||||
|
||||
let mut tv2 = tv.clone();
|
||||
tv2.splice(0..=2, None);
|
||||
assert_eq!(tv2, tiny_vec![]);
|
||||
|
||||
let mut tv2 = tv.clone();
|
||||
tv2.splice(1..=1, None);
|
||||
assert_eq!(tv2, tiny_vec![1, 3]);
|
||||
|
||||
let mut tv2 = tv.clone();
|
||||
tv2.splice(1..=2, None);
|
||||
assert_eq!(tv2, tiny_vec![1]);
|
||||
|
||||
// splice adds the elements correctly
|
||||
let mut tv2 = tv.clone();
|
||||
tv2.splice(.., 4..=6);
|
||||
assert_eq!(tv2, tiny_vec![4, 5, 6]);
|
||||
|
||||
let mut tv2 = tv.clone();
|
||||
tv2.splice(..2, 4..=6);
|
||||
assert_eq!(tv2, tiny_vec![4, 5, 6, 3]);
|
||||
|
||||
let mut tv2 = tv.clone();
|
||||
tv2.splice(..3, 4..=6);
|
||||
assert_eq!(tv2, tiny_vec![4, 5, 6]);
|
||||
|
||||
let mut tv2 = tv.clone();
|
||||
tv2.splice(..=1, 4..=6);
|
||||
assert_eq!(tv2, tiny_vec![4, 5, 6, 3]);
|
||||
|
||||
let mut tv2 = tv.clone();
|
||||
tv2.splice(..=2, 4..=6);
|
||||
assert_eq!(tv2, tiny_vec![4, 5, 6]);
|
||||
|
||||
let mut tv2 = tv.clone();
|
||||
tv2.splice(0.., 4..=6);
|
||||
assert_eq!(tv2, tiny_vec![4, 5, 6]);
|
||||
|
||||
let mut tv2 = tv.clone();
|
||||
tv2.splice(1.., 4..=6);
|
||||
assert_eq!(tv2, tiny_vec![1, 4, 5, 6]);
|
||||
|
||||
let mut tv2 = tv.clone();
|
||||
tv2.splice(0..2, 4..=6);
|
||||
assert_eq!(tv2, tiny_vec![4, 5, 6, 3]);
|
||||
|
||||
let mut tv2 = tv.clone();
|
||||
tv2.splice(0..3, 4..=6);
|
||||
assert_eq!(tv2, tiny_vec![4, 5, 6]);
|
||||
|
||||
let mut tv2 = tv.clone();
|
||||
tv2.splice(1..2, 4..=6);
|
||||
assert_eq!(tv2, tiny_vec![1, 4, 5, 6, 3]);
|
||||
|
||||
let mut tv2 = tv.clone();
|
||||
tv2.splice(1..3, 4..=6);
|
||||
assert_eq!(tv2, tiny_vec![1, 4, 5, 6]);
|
||||
|
||||
let mut tv2 = tv.clone();
|
||||
tv2.splice(0..=1, 4..=6);
|
||||
assert_eq!(tv2, tiny_vec![4, 5, 6, 3]);
|
||||
|
||||
let mut tv2 = tv.clone();
|
||||
tv2.splice(0..=2, 4..=6);
|
||||
assert_eq!(tv2, tiny_vec![4, 5, 6]);
|
||||
|
||||
let mut tv2 = tv.clone();
|
||||
tv2.splice(1..=1, 4..=6);
|
||||
assert_eq!(tv2, tiny_vec![1, 4, 5, 6, 3]);
|
||||
|
||||
let mut tv2 = tv.clone();
|
||||
tv2.splice(1..=2, 4..=6);
|
||||
assert_eq!(tv2, tiny_vec![1, 4, 5, 6]);
|
||||
|
||||
// splice adds the elements correctly when the replacement is smaller
|
||||
let mut tv2 = tv.clone();
|
||||
tv2.splice(.., Some(4));
|
||||
assert_eq!(tv2, tiny_vec![4]);
|
||||
|
||||
let mut tv2 = tv.clone();
|
||||
tv2.splice(..2, Some(4));
|
||||
assert_eq!(tv2, tiny_vec![4, 3]);
|
||||
|
||||
let mut tv2 = tv.clone();
|
||||
tv2.splice(1.., Some(4));
|
||||
assert_eq!(tv2, tiny_vec![1, 4]);
|
||||
|
||||
let mut tv2 = tv.clone();
|
||||
tv2.splice(1..=1, Some(4));
|
||||
assert_eq!(tv2, tiny_vec![1, 4, 3]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn TinyVec_resize() {
|
||||
let mut tv: TinyVec<[i32; 10]> = Default::default();
|
||||
tv.resize(20, 5);
|
||||
assert_eq!(&tv[..], &[5; 20]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn TinyVec_from_slice_impl() {
|
||||
let bigger_slice: [u8; 11] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
|
||||
let tinyvec: TinyVec<[u8; 10]> = TinyVec::Heap((&bigger_slice[..]).into());
|
||||
assert_eq!(TinyVec::from(&bigger_slice[..]), tinyvec);
|
||||
|
||||
let smaller_slice: [u8; 5] = [0, 1, 2, 3, 4];
|
||||
let tinyvec: TinyVec<[u8; 10]> = TinyVec::Inline(ArrayVec::from_array_len(
|
||||
[0, 1, 2, 3, 4, 0, 0, 0, 0, 0],
|
||||
5,
|
||||
));
|
||||
assert_eq!(TinyVec::from(&smaller_slice[..]), tinyvec);
|
||||
|
||||
let same_size: [u8; 4] = [0, 1, 2, 3];
|
||||
let tinyvec: TinyVec<[u8; 4]> =
|
||||
TinyVec::Inline(ArrayVec::from_array_len(same_size, 4));
|
||||
assert_eq!(TinyVec::from(&same_size[..]), tinyvec);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn TinyVec_from_array() {
|
||||
let array = [9, 8, 7, 6, 5, 4, 3, 2, 1];
|
||||
let tv = TinyVec::from(array);
|
||||
assert_eq!(&array, &tv[..]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn TinyVec_macro() {
|
||||
let mut expected: TinyVec<[i32; 4]> = Default::default();
|
||||
expected.push(1);
|
||||
expected.push(2);
|
||||
expected.push(3);
|
||||
|
||||
let actual = tiny_vec!(1, 2, 3);
|
||||
|
||||
assert_eq!(expected, actual);
|
||||
|
||||
assert_eq!(tiny_vec![0u8; 4], tiny_vec!(0u8, 0u8, 0u8, 0u8));
|
||||
assert_eq!(tiny_vec![0u8; 4], tiny_vec!([u8; 4] => 0, 0, 0, 0));
|
||||
assert_eq!(tiny_vec![0; 4], tiny_vec!(0, 0, 0, 0));
|
||||
assert_eq!(tiny_vec![0; 4], tiny_vec!([u8; 4] => 0, 0, 0, 0));
|
||||
|
||||
let expected2 = tiny_vec![1.1; 3];
|
||||
let actual2 = tiny_vec!([f32; 3] => 1.1, 1.1, 1.1);
|
||||
assert_eq!(expected2, actual2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn TinyVec_macro_non_copy() {
|
||||
// must use a variable here to avoid macro shenanigans
|
||||
let s = String::new();
|
||||
let _: TinyVec<[String; 10]> = tiny_vec!([String; 10] => s);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn TinyVec_reserve() {
|
||||
let mut tv: TinyVec<[i32; 4]> = Default::default();
|
||||
assert_eq!(tv.capacity(), 4);
|
||||
tv.extend_from_slice(&[1, 2]);
|
||||
assert_eq!(tv.capacity(), 4);
|
||||
tv.reserve(2);
|
||||
assert_eq!(tv.capacity(), 4);
|
||||
tv.reserve(4);
|
||||
assert!(tv.capacity() >= 6);
|
||||
tv.extend_from_slice(&[3, 4, 5, 6]);
|
||||
tv.reserve(4);
|
||||
assert!(tv.capacity() >= 10);
|
||||
}
|
||||
|
||||
#[cfg(feature = "rustc_1_57")]
|
||||
#[test]
|
||||
fn TinyVec_try_reserve() {
|
||||
let mut tv: TinyVec<[i32; 4]> = Default::default();
|
||||
assert_eq!(tv.capacity(), 4);
|
||||
tv.extend_from_slice(&[1, 2]);
|
||||
assert_eq!(tv.capacity(), 4);
|
||||
assert!(tv.try_reserve(2).is_ok());
|
||||
assert_eq!(tv.capacity(), 4);
|
||||
assert!(tv.try_reserve(4).is_ok());
|
||||
assert!(tv.capacity() >= 6);
|
||||
tv.extend_from_slice(&[3, 4, 5, 6]);
|
||||
assert!(tv.try_reserve(4).is_ok());
|
||||
assert!(tv.capacity() >= 10);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn TinyVec_reserve_exact() {
|
||||
let mut tv: TinyVec<[i32; 4]> = Default::default();
|
||||
assert_eq!(tv.capacity(), 4);
|
||||
|
||||
tv.extend_from_slice(&[1, 2]);
|
||||
assert_eq!(tv.capacity(), 4);
|
||||
tv.reserve_exact(2);
|
||||
assert_eq!(tv.capacity(), 4);
|
||||
tv.reserve_exact(4);
|
||||
assert!(tv.capacity() >= 6);
|
||||
tv.extend_from_slice(&[3, 4, 5, 6]);
|
||||
tv.reserve_exact(4);
|
||||
assert!(tv.capacity() >= 10);
|
||||
}
|
||||
|
||||
#[cfg(feature = "rustc_1_57")]
|
||||
#[test]
|
||||
fn TinyVec_try_reserve_exact() {
|
||||
let mut tv: TinyVec<[i32; 4]> = Default::default();
|
||||
assert_eq!(tv.capacity(), 4);
|
||||
|
||||
tv.extend_from_slice(&[1, 2]);
|
||||
assert_eq!(tv.capacity(), 4);
|
||||
assert!(tv.try_reserve_exact(2).is_ok());
|
||||
assert_eq!(tv.capacity(), 4);
|
||||
assert!(tv.try_reserve_exact(4).is_ok());
|
||||
assert!(tv.capacity() >= 6);
|
||||
tv.extend_from_slice(&[3, 4, 5, 6]);
|
||||
assert!(tv.try_reserve_exact(4).is_ok());
|
||||
assert!(tv.capacity() >= 10);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn TinyVec_move_to_heap_and_shrink() {
|
||||
let mut tv: TinyVec<[i32; 4]> = Default::default();
|
||||
assert!(tv.is_inline());
|
||||
tv.move_to_the_heap();
|
||||
assert!(tv.is_heap());
|
||||
assert_eq!(tv.capacity(), 0);
|
||||
|
||||
tv.push(1);
|
||||
tv.shrink_to_fit();
|
||||
assert!(tv.is_inline());
|
||||
assert_eq!(tv.capacity(), 4);
|
||||
|
||||
tv.move_to_the_heap_and_reserve(3);
|
||||
assert!(tv.is_heap());
|
||||
assert_eq!(tv.capacity(), 4);
|
||||
tv.extend(2..=4);
|
||||
assert_eq!(tv.capacity(), 4);
|
||||
assert_eq!(tv.as_slice(), [1, 2, 3, 4]);
|
||||
}
|
||||
|
||||
#[cfg(feature = "rustc_1_57")]
|
||||
#[test]
|
||||
fn TinyVec_try_move_to_heap_and_shrink() {
|
||||
let mut tv: TinyVec<[i32; 4]> = Default::default();
|
||||
assert!(tv.is_inline());
|
||||
assert!(tv.try_move_to_the_heap().is_ok());
|
||||
assert!(tv.is_heap());
|
||||
assert_eq!(tv.capacity(), 0);
|
||||
|
||||
assert!(tv.try_reserve_exact(1).is_ok());
|
||||
assert_eq!(tv.capacity(), 1);
|
||||
tv.push(1);
|
||||
tv.shrink_to_fit();
|
||||
assert!(tv.is_inline());
|
||||
assert_eq!(tv.capacity(), 4);
|
||||
|
||||
assert!(tv.try_move_to_the_heap_and_reserve(3).is_ok());
|
||||
assert!(tv.is_heap());
|
||||
assert_eq!(tv.capacity(), 4);
|
||||
tv.extend(2..=4);
|
||||
assert_eq!(tv.capacity(), 4);
|
||||
assert_eq!(tv.as_slice(), [1, 2, 3, 4]);
|
||||
}
|
||||
|
||||
#[cfg(feature = "serde")]
|
||||
#[test]
|
||||
fn TinyVec_ser_de_empty() {
|
||||
let tv: TinyVec<[i32; 0]> = tiny_vec![];
|
||||
|
||||
assert_tokens(&tv, &[Token::Seq { len: Some(0) }, Token::SeqEnd]);
|
||||
}
|
||||
|
||||
#[cfg(feature = "serde")]
|
||||
#[test]
|
||||
fn TinyVec_ser_de() {
|
||||
let tv: TinyVec<[i32; 4]> = tiny_vec![1, 2, 3, 4];
|
||||
|
||||
assert_tokens(
|
||||
&tv,
|
||||
&[
|
||||
Token::Seq { len: Some(4) },
|
||||
Token::I32(1),
|
||||
Token::I32(2),
|
||||
Token::I32(3),
|
||||
Token::I32(4),
|
||||
Token::SeqEnd,
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
#[cfg(feature = "serde")]
|
||||
#[test]
|
||||
fn TinyVec_ser_de_heap() {
|
||||
let mut tv: TinyVec<[i32; 4]> = tiny_vec![1, 2, 3, 4];
|
||||
tv.move_to_the_heap();
|
||||
|
||||
assert_tokens(
|
||||
&tv,
|
||||
&[
|
||||
Token::Seq { len: Some(4) },
|
||||
Token::I32(1),
|
||||
Token::I32(2),
|
||||
Token::I32(3),
|
||||
Token::I32(4),
|
||||
Token::SeqEnd,
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn TinyVec_pretty_debug() {
|
||||
let tv: TinyVec<[i32; 6]> = tiny_vec![1, 2, 3];
|
||||
let s = format!("{:#?}", tv);
|
||||
let expected = format!("{:#?}", tv.as_slice());
|
||||
|
||||
assert_eq!(s, expected);
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
#[test]
|
||||
fn TinyVec_std_io_write() {
|
||||
use std::io::Write;
|
||||
let mut tv: TinyVec<[u8; 3]> = TinyVec::new();
|
||||
|
||||
tv.write_all(b"foo").ok();
|
||||
assert!(tv.is_inline());
|
||||
assert_eq!(tv, tiny_vec![b'f', b'o', b'o']);
|
||||
|
||||
tv.write_all(b"bar").ok();
|
||||
assert!(tv.is_heap());
|
||||
assert_eq!(tv, tiny_vec![b'f', b'o', b'o', b'b', b'a', b'r']);
|
||||
}
|
||||
Reference in New Issue
Block a user