Vendor dependencies for 0.3.0 release

This commit is contained in:
2025-09-27 10:29:08 -05:00
parent 0c8d39d483
commit 82ab7f317b
26803 changed files with 16134934 additions and 0 deletions

1
vendor/typenum/.cargo-checksum.json vendored Normal file
View File

@@ -0,0 +1 @@
{"files":{"CHANGELOG.md":"c27add8cf18bfac90968fe0896a3300de6d1c970cbe144b862844f2a2c0922b8","Cargo.lock":"54e1e2a72e26ec356c7b89c9e4bcb43a1e0007f29d43fbc3fb75b3fa3815b5e8","Cargo.toml":"844dc4929d3245191969f3e0f7776731fac9b6182e21232b649324049cf26c16","LICENSE":"db11fec9946737df39ca3898d9cd8c10ec6f6c3a884a6802b0ad0b81b4e8f23a","LICENSE-APACHE":"516b24e051bf5630880ebbd55c40a25ce9552ebaf8970a53e8976eb70e522406","LICENSE-MIT":"a825bd853ab71619a4923d7b4311221427848070ff44d990da39b0b274c1683f","README.md":"5108073f635aa3508ec8769ca0d9a65a62a7ce7aa491f130b2a8684c2779ace0","build.rs":"5d8e1c7399d87bdaeda11bfef2654303e9c0262d2489874431fb3a191a532aa5","clippy.toml":"493258e6a4be8bbb66ecbc4236d8f4964f867d4bcddd5f13897aa655a206af7b","flake.lock":"9b078f6ce045e6f869d13d102ca84b21e60f079923a2c56baf0bf6594e8426e6","flake.nix":"7321237e292a309abf005ddf5d799df16b800406d53f2a77c3606b56532f26c5","justfile":"d356877b4443a242e53020d77f3001b23e6f0ab27b04de7222df0bc682f15a76","src/array.rs":"1f33e502de32d3a62af8c462eb804834a56a87193aa1dd27a89a9591af859e3e","src/bit.rs":"1d2a81b9dcc3fbaaad0df29e5cbd4595b02fdc3efbc08ec35932ea521ac6619c","src/gen.rs":"77e44de90067aa126d3697e514c8641af67eb9c509399bb6fcb551071d7e64ea","src/gen/consts.rs":"83fc82a4fe1e471d48f34c9e97645be1d8b427ddb9eb285a0710074a13eeeab2","src/gen/generic_const_mappings.rs":"c7646d818b834a231e9b47d14ce8cfffbafbb3828ffc5ebb49a4cb3cb70a6a31","src/gen/op.rs":"b91eadcee885bc0ab929b64492f7b04641cde71ddf8e9aa455d324f1723c61de","src/int.rs":"4adaadb711694426a6af1e7fbb54f33d668992ac0a674b77f0894a1a2213fda8","src/lib.rs":"0835f67119395f0287db38db0e1254743a7b56ae856f6aee2ede8d0dfd36db55","src/marker_traits.rs":"5a58d16edc16853b4b793a6b46068d926911273aa9dc57fd9dc64df77986b7dd","src/operator_aliases.rs":"4666925ecdd4321e28d9654bad61e34defdba7fc1e8fa7b033b2283e4b542b93","src/private.rs":"c7008d1cd4215e0fc58897ea885058879e0c700a2fe0be46784f20d612753a48","src/type_operators.rs":"c3ea12ffc00d1d438db095d48abae94af9dd46adf0b25c90871c1c4d6f15ae7b","src/uint.rs":"fd204d6fdaed7b342efabf996f8be065be511240736d651d5ac57cf3bc9df495","tests/test.rs":"92139fa86ffcacc1dff60e6fc36420c850d70dc814bd21dc18e87857553c6cea"},"package":"1dccffe3ce07af9386bfd29e80c0ab1a8205a2fc34e4bcd40364df902cfa8f3f"}

125
vendor/typenum/CHANGELOG.md vendored Normal file
View File

@@ -0,0 +1,125 @@
# Changelog
This project follows semantic versioning.
The MSRV (Minimum Supported Rust Version) is 1.37.0, and typenum is tested
against this Rust version.
### Unreleased
### 1.18.0 (2025-02-17)
- [changed] Remove build scripts; instead check-in the built code (PR #219)
- [added] Constants for 3600 (PR #220)
- [added] Elixir-style syntax for `tarr!` macro (PR #214)
- [added] `FoldAdd` and `FoldMul` to get the sum/product of an array (PR #209)
### 1.17.0 (2023-09-15)
- [removed] Remove `force_unix_path_separator` feature, make it the default
- [added] docs.rs metadata and cfg options
- [added] Playground metadata
### 1.16.0 (2022-12-05)
- [added] `const INT` field to the `ToInt` trait.
- [added] `const-generics` field with `U<N>` mapping where `N` is a const generic.
### 1.15.0 (2021-12-25)
- [fixed] Cross-compilation issue due to doing math in build script. (PR #177)
- [added] New feature `scale_info` for using inside
[Substrate](https://github.com/paritytech/substrate.git)-based runtimes (PR
#175)
### 1.14.0 (2021-09-01)
- [changed] Sealed all marker traits. Documentation already stated that these
should not be implemented outside the crate, so this is not considered a
breaking change.
### 1.13.0 (2021-03-12)
- [changed] MSRV from 1.22.0 to 1.37.0.
- [fixed] `op` macro with 2018 edition import.
- [changed] Allowed calling `assert_type_eq` and `assert_type` at top level.
- [added] Marker trait `Zero` for `Z0`, `U0`, and `B0`.
- [added] Implementation of `Pow` trait for f32 and f64 with negative exponent.
- [added] Trait `ToInt`.
### 1.12.0 (2020-04-13)
- [added] Feature `force_unix_path_separator` to support building without Cargo.
- [added] Greatest common divisor operator `Gcd` with alias `Gcf`.
- [added] `gcd` to the `op!` macro.
- [changed] Added `Copy` bound to `Rhs` of `Mul<Rhs>` impl for `<TArr<V, A>`.
- [changed] Added `Copy` bound to `Rhs` of `Div<Rhs>` impl for `<TArr<V, A>`.
- [changed] Added `Copy` bound to `Rhs` of `PartialDiv<Rhs>` impl for `<TArr<V, A>`.
- [changed] Added `Copy` bound to `Rhs` of `Rem<Rhs>` impl for `<TArr<V, A>`.
- [fixed] Make all functions #[inline].
### 1.11.2 (2019-08-26)
- [fixed] Cross compilation from Linux to Windows.
### 1.11.1 (2019-08-25)
- [fixed] Builds on earlier Rust builds again and added Rust 1.22.0 to Travis to
prevent future breakage.
### 1.11.0 (2019-08-25)
- [added] Integer `log2` to the `op!` macro.
- [added] Integer binary logarithm operator `Logarithm2` with alias `Log2`.
- [changed] Removed `feature(i128_type)` when running with the `i128`
feature. Kept the feature flag. for typenum to maintain compatibility with
old Rust versions.
- [added] Integer `sqrt` to the `op!` macro.
- [added] Integer square root operator `SquareRoot` with alias `Sqrt`.
- [fixed] Bug with attempting to create U1024 type alias twice.
### 1.10.0 (2018-03-11)
- [added] The `PowerOfTwo` marker trait.
- [added] Associated constants for `Bit`, `Unsigned`, and `Integer`.
### 1.9.0 (2017-05-14)
- [added] The `Abs` type operator and corresponding `AbsVal` alias.
- [added] The feature `i128` that enables creating 128-bit integers from
typenums.
- [added] The `assert_type!` and `assert_type_eq!` macros.
- [added] Operators to the `op!` macro, including those performed by `cmp!`.
- [fixed] Bug in `op!` macro involving functions and convoluted expressions.
- [deprecated] The `cmp!` macro.
### 1.8.0 (2017-04-12)
- [added] The `op!` macro for conveniently performing type-level operations.
- [added] The `cmp!` macro for conveniently performing type-level comparisons.
- [added] Some comparison type-operators that are used by the `cmp!` macro.
### 1.7.0 (2017-03-24)
- [added] Type operators `Min` and `Max` with accompanying aliases `Minimum` and
`Maximum`
### 1.6.0 (2017-02-24)
- [fixed] Bug in `Array` division.
- [fixed] Bug where `Rem` would sometimes exit early with the wrong answer.
- [added] `PartialDiv` operator that performs division as a partial function --
it's defined only when there is no remainder.
### 1.5.2 (2017-02-04)
- [fixed] Bug between `Div` implementation and type system.
### 1.5.1 (2016-11-08)
- [fixed] Expanded implementation of `Pow` for primitives.
### 1.5.0 (2016-11-03)
- [added] Functions to the `Pow` and `Len` traits. This is *technically* a
breaking change, but it would only break someone's code if they have a custom
impl for `Pow`. I would be very surprised if that is anyone other than me.
### 1.4.0 (2016-10-29)
- [added] Type-level arrays of type-level integers. (PR #66)
- [added] The types in this crate are now instantiable. (Issue #67, PR #68)
### 1.3.1 (2016-03-31)
- [fixed] Bug with recent nightlies.
### 1.3.0 (2016-02-07)
- [changed] Removed dependency on libstd. (Issue #53, PR #55)
- [changed] Reorganized module structure. (PR #57)
### 1.2.0 (2016-01-03)
- [added] This change log!
- [added] Convenience type aliases for operators. (Issue #48, PR #50)
- [added] Types in this crate now derive all possible traits. (Issue #42, PR
#51)

214
vendor/typenum/Cargo.lock generated vendored Normal file
View File

@@ -0,0 +1,214 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "arrayvec"
version = "0.7.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50"
[[package]]
name = "byte-slice-cast"
version = "1.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3ac9f8b63eca6fd385229b3675f6cc0dc5c8a5c8a54a59d4f52ffd670d87b0c"
[[package]]
name = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "derive_more"
version = "0.99.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3da29a38df43d6f156149c9b43ded5e018ddff2a855cf2cfd62e8cd7d079c69f"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.98",
]
[[package]]
name = "equivalent"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f"
[[package]]
name = "hashbrown"
version = "0.15.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bf151400ff0baff5465007dd2f3e717f3fe502074ca563069ce3a6629d07b289"
[[package]]
name = "impl-trait-for-tuples"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a0eb5a3343abf848c0984fe4604b2b105da9539376e24fc0a3b0007411ae4fd9"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.98",
]
[[package]]
name = "indexmap"
version = "2.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8c9c992b02b5b4c94ea26e32fe5bccb7aa7d9f390ab5c1221ff895bc7ea8b652"
dependencies = [
"equivalent",
"hashbrown",
]
[[package]]
name = "memchr"
version = "2.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
[[package]]
name = "once_cell"
version = "1.20.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "945462a4b81e43c4e3ba96bd7b49d834c6f61198356aa858733bc4acf3cbe62e"
[[package]]
name = "parity-scale-codec"
version = "2.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "373b1a4c1338d9cd3d1fa53b3a11bdab5ab6bd80a20f7f7becd76953ae2be909"
dependencies = [
"arrayvec",
"byte-slice-cast",
"impl-trait-for-tuples",
"parity-scale-codec-derive",
]
[[package]]
name = "parity-scale-codec-derive"
version = "2.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1557010476e0595c9b568d16dcfb81b93cdeb157612726f5170d31aa707bed27"
dependencies = [
"proc-macro-crate",
"proc-macro2",
"quote",
"syn 1.0.109",
]
[[package]]
name = "proc-macro-crate"
version = "1.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7f4c021e1093a56626774e81216a4ce732a735e5bad4868a03f3ed65ca0c3919"
dependencies = [
"once_cell",
"toml_edit",
]
[[package]]
name = "proc-macro2"
version = "1.0.93"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "60946a68e5f9d28b0dc1c21bb8a97ee7d018a8b322fa57838ba31cc878e22d99"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
version = "1.0.38"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0e4dccaaaf89514f546c693ddc140f729f958c247918a13380cccc6078391acc"
dependencies = [
"proc-macro2",
]
[[package]]
name = "scale-info"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c55b744399c25532d63a0d2789b109df8d46fc93752d46b0782991a931a782f"
dependencies = [
"cfg-if",
"derive_more",
"parity-scale-codec",
"scale-info-derive",
]
[[package]]
name = "scale-info-derive"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baeb2780690380592f86205aa4ee49815feb2acad8c2f59e6dd207148c3f1fcd"
dependencies = [
"proc-macro-crate",
"proc-macro2",
"quote",
"syn 1.0.109",
]
[[package]]
name = "syn"
version = "1.0.109"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "syn"
version = "2.0.98"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "36147f1a48ae0ec2b5b3bc5b537d267457555a10dc06f3dbc8cb11ba3006d3b1"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "toml_datetime"
version = "0.6.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41"
[[package]]
name = "toml_edit"
version = "0.19.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1b5bb770da30e5cbfde35a2d7b9b8a2c4b8ef89548a7a6aeab5c9a576e3e7421"
dependencies = [
"indexmap",
"toml_datetime",
"winnow",
]
[[package]]
name = "typenum"
version = "1.18.0"
dependencies = [
"scale-info",
]
[[package]]
name = "unicode-ident"
version = "1.0.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a210d160f08b701c8721ba1c726c11662f877ea6b7094007e1ca9a1041945034"
[[package]]
name = "winnow"
version = "0.5.40"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f593a95398737aeed53e489c785df13f3618e41dbcd6718c6addbf1395aa6876"
dependencies = [
"memchr",
]

73
vendor/typenum/Cargo.toml vendored Normal file
View File

@@ -0,0 +1,73 @@
# 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"
rust-version = "1.37.0"
name = "typenum"
version = "1.18.0"
authors = [
"Paho Lurie-Gregg <paho@paholg.com>",
"Andre Bogus <bogusandre@gmail.com>",
]
build = "build.rs"
autolib = false
autobins = false
autoexamples = false
autotests = false
autobenches = false
description = """
Typenum is a Rust library for type-level numbers evaluated at
compile time. It currently supports bits, unsigned integers, and signed
integers. It also provides a type-level array of type-level numbers, but its
implementation is incomplete."""
documentation = "https://docs.rs/typenum"
readme = "README.md"
categories = ["no-std"]
license = "MIT OR Apache-2.0"
repository = "https://github.com/paholg/typenum"
[package.metadata.docs.rs]
features = [
"i128",
"const-generics",
]
rustdoc-args = [
"--cfg",
"docsrs",
]
[package.metadata.playground]
features = [
"i128",
"const-generics",
]
[lib]
name = "typenum"
path = "src/lib.rs"
[[test]]
name = "test"
path = "tests/test.rs"
[dependencies.scale-info]
version = "1.0"
optional = true
default-features = false
[features]
const-generics = []
force_unix_path_separator = []
i128 = []
no_std = []
scale_info = ["scale-info/derive"]
strict = []

1
vendor/typenum/LICENSE vendored Normal file
View File

@@ -0,0 +1 @@
MIT OR Apache-2.0

201
vendor/typenum/LICENSE-APACHE vendored Normal file
View File

@@ -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 2014 Paho Lurie-Gregg
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.

21
vendor/typenum/LICENSE-MIT vendored Normal file
View File

@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2014 Paho Lurie-Gregg
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.

67
vendor/typenum/README.md vendored Normal file
View File

@@ -0,0 +1,67 @@
[![crates.io](https://img.shields.io/crates/v/typenum.svg)](https://crates.io/crates/typenum)
[![Build Status](https://github.com/paholg/typenum/actions/workflows/check.yml/badge.svg)](https://github.com/paholg/typenum/actions/workflows/check.yml)
Typenum
=====
Typenum is a Rust library for type-level numbers evaluated at compile time. It
currently supports bits, unsigned integers, and signed integers.
Typenum depends only on libcore, and so is suitable for use on any platform!
For the full documentation, go [here](https://docs.rs/typenum).
### Importing
While `typenum` is divided into several modules, they are all re-exported
through the crate root, so you can import anything contained herein with `use
typenum::whatever;`, ignoring the crate structure.
You may also find it useful to treat the `consts` module as a prelude,
performing a glob import.
### Example
Here is a trivial example of `typenum`'s use:
```rust
use typenum::{Sum, Exp, Integer, N2, P3, P4};
type X = Sum<P3, P4>;
assert_eq!(<X as Integer>::to_i32(), 7);
type Y = Exp<N2, P3>;
assert_eq!(<Y as Integer>::to_i32(), -8);
```
For a non-trivial example of its use, see one of the crates that depends on
it. The full list is
[here](https://crates.io/crates/typenum/reverse_dependencies). Of note are
[dimensioned](https://crates.io/crates/dimensioned/) which does compile-time
type checking for arbitrary unit systems and
[generic-array](https://crates.io/crates/generic-array/) which provides arrays
whose length you can generically refer to.
### Error messages
Typenum's error messages aren't great, and can be difficult to parse. The good
news is that the fine folks at Auxon have written a tool to help with it. Please
take a look at [tnfilt](https://github.com/auxoncorp/tnfilt).
### License
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 the work by you, as defined in the Apache-2.0 license, shall be
dual licensed as above, without any additional terms or conditions.

417
vendor/typenum/build.rs vendored Normal file
View File

@@ -0,0 +1,417 @@
use std::{cmp, env, fmt, fs::File, io::Write, path::PathBuf};
enum UIntCode {
Term,
Zero(Box<UIntCode>),
One(Box<UIntCode>),
}
enum IntCode {
Zero,
Pos(Box<UIntCode>),
Neg(Box<UIntCode>),
}
impl fmt::Display for UIntCode {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
UIntCode::Term => write!(f, "UTerm"),
UIntCode::Zero(ref inner) => write!(f, "UInt<{}, B0>", inner),
UIntCode::One(ref inner) => write!(f, "UInt<{}, B1>", inner),
}
}
}
impl fmt::Display for IntCode {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
IntCode::Zero => write!(f, "Z0"),
IntCode::Pos(ref inner) => write!(f, "PInt<{}>", inner),
IntCode::Neg(ref inner) => write!(f, "NInt<{}>", inner),
}
}
}
fn gen_uint(u: u64) -> UIntCode {
let mut result = UIntCode::Term;
let mut x = 1u64 << 63;
while x > u {
x >>= 1
}
while x > 0 {
result = if x & u > 0 {
UIntCode::One(Box::new(result))
} else {
UIntCode::Zero(Box::new(result))
};
x >>= 1;
}
result
}
fn gen_int(i: i64) -> IntCode {
use std::cmp::Ordering::{Equal, Greater, Less};
match i.cmp(&0) {
Greater => IntCode::Pos(Box::new(gen_uint(i as u64))),
Less => IntCode::Neg(Box::new(gen_uint(i.abs() as u64))),
Equal => IntCode::Zero,
}
}
/// Computes the greatest common divisor of two integers.
fn gcdi(mut a: i64, mut b: i64) -> i64 {
a = a.abs();
b = b.abs();
while a != 0 {
let tmp = b % a;
b = a;
a = tmp;
}
b
}
fn gcdu(mut a: u64, mut b: u64) -> u64 {
while a != 0 {
let tmp = b % a;
b = a;
a = tmp;
}
b
}
fn sign(i: i64) -> char {
use std::cmp::Ordering::*;
match i.cmp(&0) {
Greater => 'P',
Less => 'N',
Equal => '_',
}
}
struct UIntTest {
a: u64,
op: &'static str,
b: Option<u64>,
r: u64,
}
impl fmt::Display for UIntTest {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self.b {
Some(b) => write!(
f,
"
#[test]
#[allow(non_snake_case)]
fn test_{a}_{op}_{b}() {{
type A = {gen_a};
type B = {gen_b};
type U{r} = {result};
#[allow(non_camel_case_types)]
type U{a}{op}U{b} = <<A as {op}<B>>::Output as Same<U{r}>>::Output;
assert_eq!(<U{a}{op}U{b} as Unsigned>::to_u64(), <U{r} as Unsigned>::to_u64());
}}",
gen_a = gen_uint(self.a),
gen_b = gen_uint(b),
r = self.r,
result = gen_uint(self.r),
a = self.a,
b = b,
op = self.op
),
None => write!(
f,
"
#[test]
#[allow(non_snake_case)]
fn test_{a}_{op}() {{
type A = {gen_a};
type U{r} = {result};
#[allow(non_camel_case_types)]
type {op}U{a} = <<A as {op}>::Output as Same<U{r}>>::Output;
assert_eq!(<{op}U{a} as Unsigned>::to_u64(), <U{r} as Unsigned>::to_u64());
}}",
gen_a = gen_uint(self.a),
r = self.r,
result = gen_uint(self.r),
a = self.a,
op = self.op
),
}
}
}
fn uint_binary_test(left: u64, operator: &'static str, right: u64, result: u64) -> UIntTest {
UIntTest {
a: left,
op: operator,
b: Option::Some(right),
r: result,
}
}
struct IntBinaryTest {
a: i64,
op: &'static str,
b: i64,
r: i64,
}
impl fmt::Display for IntBinaryTest {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(
f,
"
#[test]
#[allow(non_snake_case)]
fn test_{sa}{a}_{op}_{sb}{b}() {{
type A = {gen_a};
type B = {gen_b};
type {sr}{r} = {result};
#[allow(non_camel_case_types)]
type {sa}{a}{op}{sb}{b} = <<A as {op}<B>>::Output as Same<{sr}{r}>>::Output;
assert_eq!(<{sa}{a}{op}{sb}{b} as Integer>::to_i64(), <{sr}{r} as Integer>::to_i64());
}}",
gen_a = gen_int(self.a),
gen_b = gen_int(self.b),
r = self.r.abs(),
sr = sign(self.r),
result = gen_int(self.r),
a = self.a.abs(),
b = self.b.abs(),
sa = sign(self.a),
sb = sign(self.b),
op = self.op
)
}
}
fn int_binary_test(left: i64, operator: &'static str, right: i64, result: i64) -> IntBinaryTest {
IntBinaryTest {
a: left,
op: operator,
b: right,
r: result,
}
}
struct IntUnaryTest {
op: &'static str,
a: i64,
r: i64,
}
impl fmt::Display for IntUnaryTest {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(
f,
"
#[test]
#[allow(non_snake_case)]
fn test_{sa}{a}_{op}() {{
type A = {gen_a};
type {sr}{r} = {result};
#[allow(non_camel_case_types)]
type {op}{sa}{a} = <<A as {op}>::Output as Same<{sr}{r}>>::Output;
assert_eq!(<{op}{sa}{a} as Integer>::to_i64(), <{sr}{r} as Integer>::to_i64());
}}",
gen_a = gen_int(self.a),
r = self.r.abs(),
sr = sign(self.r),
result = gen_int(self.r),
a = self.a.abs(),
sa = sign(self.a),
op = self.op
)
}
}
fn int_unary_test(operator: &'static str, num: i64, result: i64) -> IntUnaryTest {
IntUnaryTest {
op: operator,
a: num,
r: result,
}
}
fn uint_cmp_test(a: u64, b: u64) -> String {
format!(
"
#[test]
#[allow(non_snake_case)]
fn test_{a}_Cmp_{b}() {{
type A = {gen_a};
type B = {gen_b};
#[allow(non_camel_case_types)]
type U{a}CmpU{b} = <A as Cmp<B>>::Output;
assert_eq!(<U{a}CmpU{b} as Ord>::to_ordering(), Ordering::{result:?});
}}",
a = a,
b = b,
gen_a = gen_uint(a),
gen_b = gen_uint(b),
result = a.cmp(&b)
)
}
fn int_cmp_test(a: i64, b: i64) -> String {
format!(
"
#[test]
#[allow(non_snake_case)]
fn test_{sa}{a}_Cmp_{sb}{b}() {{
type A = {gen_a};
type B = {gen_b};
#[allow(non_camel_case_types)]
type {sa}{a}Cmp{sb}{b} = <A as Cmp<B>>::Output;
assert_eq!(<{sa}{a}Cmp{sb}{b} as Ord>::to_ordering(), Ordering::{result:?});
}}",
a = a.abs(),
b = b.abs(),
sa = sign(a),
sb = sign(b),
gen_a = gen_int(a),
gen_b = gen_int(b),
result = a.cmp(&b)
)
}
pub fn gen_tests() -> String {
// will test all permutations of number pairs up to this (and down to its opposite for ints)
let high: i64 = 5;
let uints = (0u64..high as u64 + 1).flat_map(|a| (a..a + 1).cycle().zip(0..high as u64 + 1));
let ints = (-high..high + 1).flat_map(|a| (a..a + 1).cycle().zip(-high..high + 1));
let mut result = String::new();
result.push_str(
"
use typenum::*;
use core::ops::*;
use core::cmp::Ordering;
",
);
// uint operators:
for (a, b) in uints {
let mut tests = vec![
uint_binary_test(a, "BitAnd", b, a & b),
uint_binary_test(a, "BitOr", b, a | b),
uint_binary_test(a, "BitXor", b, a ^ b),
uint_binary_test(a, "Shl", b, a << b),
uint_binary_test(a, "Shr", b, a >> b),
uint_binary_test(a, "Add", b, a + b),
uint_binary_test(a, "Mul", b, a * b),
uint_binary_test(a, "Pow", b, a.pow(b as u32)),
uint_binary_test(a, "Min", b, cmp::min(a, b)),
uint_binary_test(a, "Max", b, cmp::max(a, b)),
uint_binary_test(a, "Gcd", b, gcdu(a, b)),
];
if a >= b {
tests.push(uint_binary_test(a, "Sub", b, a - b));
}
if b != 0 {
tests.push(uint_binary_test(a, "Div", b, a / b));
tests.push(uint_binary_test(a, "Rem", b, a % b));
if a % b == 0 {
tests.push(uint_binary_test(a, "PartialDiv", b, a / b));
}
}
for test in tests {
result.push_str(&test.to_string());
}
result.push_str(&uint_cmp_test(a, b));
}
// int operators:
for (a, b) in ints {
let mut tests = vec![
int_binary_test(a, "Add", b, a + b),
int_binary_test(a, "Sub", b, a - b),
int_binary_test(a, "Mul", b, a * b),
int_binary_test(a, "Min", b, cmp::min(a, b)),
int_binary_test(a, "Max", b, cmp::max(a, b)),
int_binary_test(a, "Gcd", b, gcdi(a, b)),
];
if b != 0 {
tests.push(int_binary_test(a, "Div", b, a / b));
tests.push(int_binary_test(a, "Rem", b, a % b));
if a % b == 0 {
tests.push(int_binary_test(a, "PartialDiv", b, a / b));
}
}
if b >= 0 || a.abs() == 1 {
let result = if b < 0 {
if a == 1 {
a
} else if a == -1 {
a.pow((-b) as u32)
} else {
unreachable!()
}
} else {
a.pow(b as u32)
};
tests.push(int_binary_test(a, "Pow", b, result));
}
for test in tests {
result.push_str(&test.to_string());
}
result.push_str(&int_cmp_test(a, b));
}
// int unary operators:
for n in -high..high + 1 {
let tests = vec![
int_unary_test("Neg", n, -n),
int_unary_test("Abs", n, n.abs()),
];
for test in tests {
result.push_str(&test.to_string());
}
}
result
}
#[cfg_attr(
feature = "no_std",
deprecated(
since = "1.3.0",
note = "the `no_std` flag is no longer necessary and will be removed in the future"
)
)]
pub fn no_std() {}
#[cfg_attr(
feature = "force_unix_path_separator",
deprecated(
since = "1.17.0",
note = "the `force_unix_path_separator` flag is no longer necessary and will be removed in the future"
)
)]
pub fn force_unix_path_separator() {}
fn main() {
no_std();
force_unix_path_separator();
println!("cargo:rerun-if-changed=tests");
let tests = gen_tests();
let out_dir = env::var("OUT_DIR").unwrap();
let dest = PathBuf::from(out_dir).join("tests.rs");
let mut f = File::create(&dest).unwrap();
f.write_all(tests.as_bytes()).unwrap();
}

1
vendor/typenum/clippy.toml vendored Normal file
View File

@@ -0,0 +1 @@
cognitive-complexity-threshold=35

95
vendor/typenum/flake.lock generated vendored Normal file
View File

@@ -0,0 +1,95 @@
{
"nodes": {
"flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1731533236,
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1739736696,
"narHash": "sha256-zON2GNBkzsIyALlOCFiEBcIjI4w38GYOb+P+R4S8Jsw=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "d74a2335ac9c133d6bbec9fc98d91a77f1604c1f",
"type": "github"
},
"original": {
"id": "nixpkgs",
"ref": "nixos-unstable",
"type": "indirect"
}
},
"nixpkgs_2": {
"locked": {
"lastModified": 1736320768,
"narHash": "sha256-nIYdTAiKIGnFNugbomgBJR+Xv5F1ZQU+HfaBqJKroC0=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "4bc9c909d9ac828a039f288cf872d16d38185db8",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs",
"rust-overlay": "rust-overlay"
}
},
"rust-overlay": {
"inputs": {
"nixpkgs": "nixpkgs_2"
},
"locked": {
"lastModified": 1739759407,
"narHash": "sha256-YIrVxD2SaUyaEdMry2nAd2qG1E0V38QIV6t6rpguFwk=",
"owner": "oxalica",
"repo": "rust-overlay",
"rev": "6e6ae2acf4221380140c22d65b6c41f4726f5932",
"type": "github"
},
"original": {
"owner": "oxalica",
"repo": "rust-overlay",
"type": "github"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
}
},
"root": "root",
"version": 7
}

42
vendor/typenum/flake.nix vendored Normal file
View File

@@ -0,0 +1,42 @@
{
inputs = {
nixpkgs.url = "nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
rust-overlay.url = "github:oxalica/rust-overlay";
};
outputs =
{
nixpkgs,
flake-utils,
rust-overlay,
...
}:
flake-utils.lib.eachDefaultSystem (
system:
let
overlays = [
(import rust-overlay)
];
pkgs = import nixpkgs {
inherit system overlays;
};
rust = pkgs.rust-bin.stable.latest.default.override {
extensions = [
"rust-analyzer"
"rust-src"
];
};
in
{
devShells.default = pkgs.mkShell {
packages = [
pkgs.just
rust
];
};
}
);
}

34
vendor/typenum/justfile vendored Normal file
View File

@@ -0,0 +1,34 @@
# Generate code and run lints and tests
test-local: gen lint test
@just test --features const-generics
# Produce generated code
gen:
cargo run --package generate
cargo fmt
# Update lockfiles
up:
nix flake update
cargo update
# Run all lints
lint: fmt-check clippy clippy-all
# Check formatting
fmt-check:
cargo fmt --all -- --check
# Clippy
clippy:
cargo clippy -- -D warnings
# Clippy with all features
clippy-all:
# Allow deprecated because we test the no_std feature.
cargo clippy --all-features -- -D warnings -A deprecated
# Run test
test *args:
cargo test --verbose --features "strict" {{args}}
cargo doc --features "strict" {{args}}

396
vendor/typenum/src/array.rs vendored Normal file
View File

@@ -0,0 +1,396 @@
//! A type-level array of type-level numbers.
//!
//! It is not very featureful right now, and should be considered a work in progress.
use core::ops::{Add, Div, Mul, Sub};
use super::*;
/// The terminating type for type arrays.
#[derive(Eq, PartialEq, Ord, PartialOrd, Clone, Copy, Hash, Debug)]
#[cfg_attr(feature = "scale_info", derive(scale_info::TypeInfo))]
pub struct ATerm;
impl TypeArray for ATerm {}
/// `TArr` is a type that acts as an array of types. It is defined similarly to `UInt`, only its
/// values can be more than bits, and it is designed to act as an array. So you can only add two if
/// they have the same number of elements, for example.
///
/// This array is only really designed to contain `Integer` types. If you use it with others, you
/// may find it lacking functionality.
#[derive(Eq, PartialEq, Ord, PartialOrd, Clone, Copy, Hash, Debug)]
#[cfg_attr(feature = "scale_info", derive(scale_info::TypeInfo))]
pub struct TArr<V, A> {
first: V,
rest: A,
}
impl<V, A> TypeArray for TArr<V, A> {}
/// Create a new type-level array. Only usable on Rust 1.13.0 or newer.
///
/// There's not a whole lot you can do with it right now.
///
/// # Example
/// ```rust
/// #[macro_use]
/// extern crate typenum;
/// use typenum::consts::*;
///
/// type Array = tarr![P3, N4, Z0, P38];
/// # fn main() { let _: Array; }
#[macro_export]
macro_rules! tarr {
() => ( $crate::ATerm );
($n:ty) => ( $crate::TArr<$n, $crate::ATerm> );
($n:ty,) => ( $crate::TArr<$n, $crate::ATerm> );
($n:ty, $($tail:ty),+) => ( $crate::TArr<$n, tarr![$($tail),+]> );
($n:ty, $($tail:ty),+,) => ( $crate::TArr<$n, tarr![$($tail),+]> );
($n:ty | $rest:ty) => ( $crate::TArr<$n, $rest> );
($n:ty, $($tail:ty),+ | $rest:ty) => ( $crate::TArr<$n, ta![$($tail),+ | $rest]> );
}
// ---------------------------------------------------------------------------------------
// Length
/// Length of `ATerm` by itself is 0
impl Len for ATerm {
type Output = U0;
#[inline]
fn len(&self) -> Self::Output {
UTerm
}
}
/// Size of a `TypeArray`
impl<V, A> Len for TArr<V, A>
where
A: Len,
Length<A>: Add<B1>,
Sum<Length<A>, B1>: Unsigned,
{
type Output = Add1<Length<A>>;
#[inline]
fn len(&self) -> Self::Output {
self.rest.len() + B1
}
}
// ---------------------------------------------------------------------------------------
// FoldAdd
/// Hide our `Null` type
const _: () = {
/// A type which contributes nothing when adding (i.e. a zero)
pub struct Null;
impl<T> Add<T> for Null {
type Output = T;
fn add(self, rhs: T) -> Self::Output {
rhs
}
}
impl FoldAdd for ATerm {
type Output = Null;
}
};
impl<V, A> FoldAdd for TArr<V, A>
where
A: FoldAdd,
FoldSum<A>: Add<V>,
{
type Output = Sum<FoldSum<A>, V>;
}
// ---------------------------------------------------------------------------------------
// FoldMul
/// Hide our `Null` type
const _: () = {
/// A type which contributes nothing when multiplying (i.e. a one)
pub struct Null;
impl<T> Mul<T> for Null {
type Output = T;
fn mul(self, rhs: T) -> Self::Output {
rhs
}
}
impl FoldMul for ATerm {
type Output = Null;
}
};
impl<V, A> FoldMul for TArr<V, A>
where
A: FoldMul,
FoldProd<A>: Mul<V>,
{
type Output = Prod<FoldProd<A>, V>;
}
// ---------------------------------------------------------------------------------------
// Add arrays
// Note that two arrays are only addable if they are the same length.
impl Add<ATerm> for ATerm {
type Output = ATerm;
#[inline]
fn add(self, _: ATerm) -> Self::Output {
ATerm
}
}
impl<Al, Vl, Ar, Vr> Add<TArr<Vr, Ar>> for TArr<Vl, Al>
where
Al: Add<Ar>,
Vl: Add<Vr>,
{
type Output = TArr<Sum<Vl, Vr>, Sum<Al, Ar>>;
#[inline]
fn add(self, rhs: TArr<Vr, Ar>) -> Self::Output {
TArr {
first: self.first + rhs.first,
rest: self.rest + rhs.rest,
}
}
}
// ---------------------------------------------------------------------------------------
// Subtract arrays
// Note that two arrays are only subtractable if they are the same length.
impl Sub<ATerm> for ATerm {
type Output = ATerm;
#[inline]
fn sub(self, _: ATerm) -> Self::Output {
ATerm
}
}
impl<Vl, Al, Vr, Ar> Sub<TArr<Vr, Ar>> for TArr<Vl, Al>
where
Vl: Sub<Vr>,
Al: Sub<Ar>,
{
type Output = TArr<Diff<Vl, Vr>, Diff<Al, Ar>>;
#[inline]
fn sub(self, rhs: TArr<Vr, Ar>) -> Self::Output {
TArr {
first: self.first - rhs.first,
rest: self.rest - rhs.rest,
}
}
}
// ---------------------------------------------------------------------------------------
// Multiply an array by a scalar
impl<Rhs> Mul<Rhs> for ATerm {
type Output = ATerm;
#[inline]
fn mul(self, _: Rhs) -> Self::Output {
ATerm
}
}
impl<V, A, Rhs> Mul<Rhs> for TArr<V, A>
where
V: Mul<Rhs>,
A: Mul<Rhs>,
Rhs: Copy,
{
type Output = TArr<Prod<V, Rhs>, Prod<A, Rhs>>;
#[inline]
fn mul(self, rhs: Rhs) -> Self::Output {
TArr {
first: self.first * rhs,
rest: self.rest * rhs,
}
}
}
impl Mul<ATerm> for Z0 {
type Output = ATerm;
#[inline]
fn mul(self, _: ATerm) -> Self::Output {
ATerm
}
}
impl<U> Mul<ATerm> for PInt<U>
where
U: Unsigned + NonZero,
{
type Output = ATerm;
#[inline]
fn mul(self, _: ATerm) -> Self::Output {
ATerm
}
}
impl<U> Mul<ATerm> for NInt<U>
where
U: Unsigned + NonZero,
{
type Output = ATerm;
#[inline]
fn mul(self, _: ATerm) -> Self::Output {
ATerm
}
}
impl<V, A> Mul<TArr<V, A>> for Z0
where
Z0: Mul<A>,
{
type Output = TArr<Z0, Prod<Z0, A>>;
#[inline]
fn mul(self, rhs: TArr<V, A>) -> Self::Output {
TArr {
first: Z0,
rest: self * rhs.rest,
}
}
}
impl<V, A, U> Mul<TArr<V, A>> for PInt<U>
where
U: Unsigned + NonZero,
PInt<U>: Mul<A> + Mul<V>,
{
type Output = TArr<Prod<PInt<U>, V>, Prod<PInt<U>, A>>;
#[inline]
fn mul(self, rhs: TArr<V, A>) -> Self::Output {
TArr {
first: self * rhs.first,
rest: self * rhs.rest,
}
}
}
impl<V, A, U> Mul<TArr<V, A>> for NInt<U>
where
U: Unsigned + NonZero,
NInt<U>: Mul<A> + Mul<V>,
{
type Output = TArr<Prod<NInt<U>, V>, Prod<NInt<U>, A>>;
#[inline]
fn mul(self, rhs: TArr<V, A>) -> Self::Output {
TArr {
first: self * rhs.first,
rest: self * rhs.rest,
}
}
}
// ---------------------------------------------------------------------------------------
// Divide an array by a scalar
impl<Rhs> Div<Rhs> for ATerm {
type Output = ATerm;
#[inline]
fn div(self, _: Rhs) -> Self::Output {
ATerm
}
}
impl<V, A, Rhs> Div<Rhs> for TArr<V, A>
where
V: Div<Rhs>,
A: Div<Rhs>,
Rhs: Copy,
{
type Output = TArr<Quot<V, Rhs>, Quot<A, Rhs>>;
#[inline]
fn div(self, rhs: Rhs) -> Self::Output {
TArr {
first: self.first / rhs,
rest: self.rest / rhs,
}
}
}
// ---------------------------------------------------------------------------------------
// Partial Divide an array by a scalar
impl<Rhs> PartialDiv<Rhs> for ATerm {
type Output = ATerm;
#[inline]
fn partial_div(self, _: Rhs) -> Self::Output {
ATerm
}
}
impl<V, A, Rhs> PartialDiv<Rhs> for TArr<V, A>
where
V: PartialDiv<Rhs>,
A: PartialDiv<Rhs>,
Rhs: Copy,
{
type Output = TArr<PartialQuot<V, Rhs>, PartialQuot<A, Rhs>>;
#[inline]
fn partial_div(self, rhs: Rhs) -> Self::Output {
TArr {
first: self.first.partial_div(rhs),
rest: self.rest.partial_div(rhs),
}
}
}
// ---------------------------------------------------------------------------------------
// Modulo an array by a scalar
use core::ops::Rem;
impl<Rhs> Rem<Rhs> for ATerm {
type Output = ATerm;
#[inline]
fn rem(self, _: Rhs) -> Self::Output {
ATerm
}
}
impl<V, A, Rhs> Rem<Rhs> for TArr<V, A>
where
V: Rem<Rhs>,
A: Rem<Rhs>,
Rhs: Copy,
{
type Output = TArr<Mod<V, Rhs>, Mod<A, Rhs>>;
#[inline]
fn rem(self, rhs: Rhs) -> Self::Output {
TArr {
first: self.first % rhs,
rest: self.rest % rhs,
}
}
}
// ---------------------------------------------------------------------------------------
// Negate an array
use core::ops::Neg;
impl Neg for ATerm {
type Output = ATerm;
#[inline]
fn neg(self) -> Self::Output {
ATerm
}
}
impl<V, A> Neg for TArr<V, A>
where
V: Neg,
A: Neg,
{
type Output = TArr<Negate<V>, Negate<A>>;
#[inline]
fn neg(self) -> Self::Output {
TArr {
first: -self.first,
rest: -self.rest,
}
}
}

347
vendor/typenum/src/bit.rs vendored Normal file
View File

@@ -0,0 +1,347 @@
//! Type-level bits.
//!
//! These are rather simple and are used as the building blocks of the
//! other number types in this crate.
//!
//!
//! **Type operators** implemented:
//!
//! - From `core::ops`: `BitAnd`, `BitOr`, `BitXor`, and `Not`.
//! - From `typenum`: `Same` and `Cmp`.
use crate::{private::InternalMarker, Cmp, Equal, Greater, Less, NonZero, PowerOfTwo, Zero};
use core::ops::{BitAnd, BitOr, BitXor, Not};
pub use crate::marker_traits::Bit;
/// The type-level bit 0.
#[derive(Eq, PartialEq, Ord, PartialOrd, Clone, Copy, Hash, Debug, Default)]
#[cfg_attr(feature = "scale_info", derive(scale_info::TypeInfo))]
pub struct B0;
impl B0 {
/// Instantiates a singleton representing this bit.
#[inline]
pub fn new() -> B0 {
B0
}
}
/// The type-level bit 1.
#[derive(Eq, PartialEq, Ord, PartialOrd, Clone, Copy, Hash, Debug, Default)]
#[cfg_attr(feature = "scale_info", derive(scale_info::TypeInfo))]
pub struct B1;
impl B1 {
/// Instantiates a singleton representing this bit.
#[inline]
pub fn new() -> B1 {
B1
}
}
impl Bit for B0 {
const U8: u8 = 0;
const BOOL: bool = false;
#[inline]
fn new() -> Self {
Self
}
#[inline]
fn to_u8() -> u8 {
0
}
#[inline]
fn to_bool() -> bool {
false
}
}
impl Bit for B1 {
const U8: u8 = 1;
const BOOL: bool = true;
#[inline]
fn new() -> Self {
Self
}
#[inline]
fn to_u8() -> u8 {
1
}
#[inline]
fn to_bool() -> bool {
true
}
}
impl Zero for B0 {}
impl NonZero for B1 {}
impl PowerOfTwo for B1 {}
/// Not of 0 (!0 = 1)
impl Not for B0 {
type Output = B1;
#[inline]
fn not(self) -> Self::Output {
B1
}
}
/// Not of 1 (!1 = 0)
impl Not for B1 {
type Output = B0;
#[inline]
fn not(self) -> Self::Output {
B0
}
}
/// And with 0 ( 0 & B = 0)
impl<Rhs: Bit> BitAnd<Rhs> for B0 {
type Output = B0;
#[inline]
fn bitand(self, _: Rhs) -> Self::Output {
B0
}
}
/// And with 1 ( 1 & 0 = 0)
impl BitAnd<B0> for B1 {
type Output = B0;
#[inline]
fn bitand(self, _: B0) -> Self::Output {
B0
}
}
/// And with 1 ( 1 & 1 = 1)
impl BitAnd<B1> for B1 {
type Output = B1;
#[inline]
fn bitand(self, _: B1) -> Self::Output {
B1
}
}
/// Or with 0 ( 0 | 0 = 0)
impl BitOr<B0> for B0 {
type Output = B0;
#[inline]
fn bitor(self, _: B0) -> Self::Output {
B0
}
}
/// Or with 0 ( 0 | 1 = 1)
impl BitOr<B1> for B0 {
type Output = B1;
#[inline]
fn bitor(self, _: B1) -> Self::Output {
B1
}
}
/// Or with 1 ( 1 | B = 1)
impl<Rhs: Bit> BitOr<Rhs> for B1 {
type Output = B1;
#[inline]
fn bitor(self, _: Rhs) -> Self::Output {
B1
}
}
/// Xor between 0 and 0 ( 0 ^ 0 = 0)
impl BitXor<B0> for B0 {
type Output = B0;
#[inline]
fn bitxor(self, _: B0) -> Self::Output {
B0
}
}
/// Xor between 1 and 0 ( 1 ^ 0 = 1)
impl BitXor<B0> for B1 {
type Output = B1;
#[inline]
fn bitxor(self, _: B0) -> Self::Output {
B1
}
}
/// Xor between 0 and 1 ( 0 ^ 1 = 1)
impl BitXor<B1> for B0 {
type Output = B1;
#[inline]
fn bitxor(self, _: B1) -> Self::Output {
B1
}
}
/// Xor between 1 and 1 ( 1 ^ 1 = 0)
impl BitXor<B1> for B1 {
type Output = B0;
#[inline]
fn bitxor(self, _: B1) -> Self::Output {
B0
}
}
#[cfg(test)]
mod bit_op_tests {
use core::ops::{BitAnd, BitOr, BitXor, Not};
use crate::{B0, B1};
// macro for testing operation results. Uses `Same` to ensure the types are equal and
// not just the values they evaluate to.
macro_rules! test_bit_op {
($op:ident $Lhs:ident = $Answer:ident) => {{
type Test = <<$Lhs as $op>::Output as $crate::Same<$Answer>>::Output;
assert_eq!(
<$Answer as $crate::Bit>::to_u8(),
<Test as $crate::Bit>::to_u8()
);
}};
($Lhs:ident $op:ident $Rhs:ident = $Answer:ident) => {{
type Test = <<$Lhs as $op<$Rhs>>::Output as $crate::Same<$Answer>>::Output;
assert_eq!(
<$Answer as $crate::Bit>::to_u8(),
<Test as $crate::Bit>::to_u8()
);
}};
}
#[test]
fn bit_operations() {
test_bit_op!(Not B0 = B1);
test_bit_op!(Not B1 = B0);
test_bit_op!(B0 BitAnd B0 = B0);
test_bit_op!(B0 BitAnd B1 = B0);
test_bit_op!(B1 BitAnd B0 = B0);
test_bit_op!(B1 BitAnd B1 = B1);
test_bit_op!(B0 BitOr B0 = B0);
test_bit_op!(B0 BitOr B1 = B1);
test_bit_op!(B1 BitOr B0 = B1);
test_bit_op!(B1 BitOr B1 = B1);
test_bit_op!(B0 BitXor B0 = B0);
test_bit_op!(B0 BitXor B1 = B1);
test_bit_op!(B1 BitXor B0 = B1);
test_bit_op!(B1 BitXor B1 = B0);
}
}
impl Cmp<B0> for B0 {
type Output = Equal;
#[inline]
fn compare<P: InternalMarker>(&self, _: &B0) -> Self::Output {
Equal
}
}
impl Cmp<B1> for B0 {
type Output = Less;
#[inline]
fn compare<P: InternalMarker>(&self, _: &B1) -> Self::Output {
Less
}
}
impl Cmp<B0> for B1 {
type Output = Greater;
#[inline]
fn compare<P: InternalMarker>(&self, _: &B0) -> Self::Output {
Greater
}
}
impl Cmp<B1> for B1 {
type Output = Equal;
#[inline]
fn compare<P: InternalMarker>(&self, _: &B1) -> Self::Output {
Equal
}
}
use crate::Min;
impl Min<B0> for B0 {
type Output = B0;
#[inline]
fn min(self, _: B0) -> B0 {
self
}
}
impl Min<B1> for B0 {
type Output = B0;
#[inline]
fn min(self, _: B1) -> B0 {
self
}
}
impl Min<B0> for B1 {
type Output = B0;
#[inline]
fn min(self, rhs: B0) -> B0 {
rhs
}
}
impl Min<B1> for B1 {
type Output = B1;
#[inline]
fn min(self, _: B1) -> B1 {
self
}
}
use crate::Max;
impl Max<B0> for B0 {
type Output = B0;
#[inline]
fn max(self, _: B0) -> B0 {
self
}
}
impl Max<B1> for B0 {
type Output = B1;
#[inline]
fn max(self, rhs: B1) -> B1 {
rhs
}
}
impl Max<B0> for B1 {
type Output = B1;
#[inline]
fn max(self, _: B0) -> B1 {
self
}
}
impl Max<B1> for B1 {
type Output = B1;
#[inline]
fn max(self, _: B1) -> B1 {
self
}
}
#[cfg(test)]
mod bit_creation_tests {
#[test]
fn bit_creation() {
{
use crate::{B0, B1};
let _: B0 = B0::new();
let _: B1 = B1::new();
}
{
use crate::{Bit, B0, B1};
let _: B0 = <B0 as Bit>::new();
let _: B1 = <B1 as Bit>::new();
}
}
}

4
vendor/typenum/src/gen.rs vendored Normal file
View File

@@ -0,0 +1,4 @@
pub mod consts;
#[cfg(feature = "const-generics")]
pub mod generic_const_mappings;
pub mod op;

5899
vendor/typenum/src/gen/consts.rs vendored Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

1030
vendor/typenum/src/gen/op.rs vendored Normal file

File diff suppressed because it is too large Load Diff

1401
vendor/typenum/src/int.rs vendored Normal file

File diff suppressed because it is too large Load Diff

175
vendor/typenum/src/lib.rs vendored Normal file
View File

@@ -0,0 +1,175 @@
//! This crate provides type-level numbers evaluated at compile time. It depends only on libcore.
//!
//! The traits defined or used in this crate are used in a typical manner. They can be divided into
//! two categories: **marker traits** and **type operators**.
//!
//! Many of the marker traits have functions defined, but they all do essentially the same thing:
//! convert a type into its runtime counterpart, and are really just there for debugging. For
//! example,
//!
//! ```rust
//! use typenum::{Integer, N4};
//!
//! assert_eq!(N4::to_i32(), -4);
//! ```
//!
//! **Type operators** are traits that behave as functions at the type level. These are the meat of
//! this library. Where possible, traits defined in libcore have been used, but their attached
//! functions have not been implemented.
//!
//! For example, the `Add` trait is implemented for both unsigned and signed integers, but the
//! `add` function is not. As there are never any objects of the types defined here, it wouldn't
//! make sense to implement it. What is important is its associated type `Output`, which is where
//! the addition happens.
//!
//! ```rust
//! use std::ops::Add;
//! use typenum::{Integer, P3, P4};
//!
//! type X = <P3 as Add<P4>>::Output;
//! assert_eq!(<X as Integer>::to_i32(), 7);
//! ```
//!
//! In addition, helper aliases are defined for type operators. For example, the above snippet
//! could be replaced with
//!
//! ```rust
//! use typenum::{Integer, Sum, P3, P4};
//!
//! type X = Sum<P3, P4>;
//! assert_eq!(<X as Integer>::to_i32(), 7);
//! ```
//!
//! Documented in each module is the full list of type operators implemented.
#![no_std]
#![forbid(unsafe_code)]
#![warn(missing_docs)]
#![cfg_attr(feature = "strict", deny(missing_docs))]
#![cfg_attr(feature = "strict", deny(warnings))]
#![doc(html_root_url = "https://docs.rs/typenum/1.18.0")]
#![cfg_attr(docsrs, feature(doc_auto_cfg, doc_cfg))]
// For debugging macros:
// #![feature(trace_macros)]
// trace_macros!(true);
use core::cmp::Ordering;
pub mod bit;
mod gen;
pub mod int;
pub mod marker_traits;
pub mod operator_aliases;
pub mod private;
pub mod type_operators;
pub mod uint;
pub mod array;
pub use crate::{
array::{ATerm, TArr},
gen::consts,
int::{NInt, PInt},
marker_traits::*,
operator_aliases::*,
type_operators::*,
uint::{UInt, UTerm},
};
#[doc(no_inline)]
#[rustfmt::skip]
pub use consts::*;
#[cfg(feature = "const-generics")]
pub use crate::gen::generic_const_mappings;
#[cfg(feature = "const-generics")]
#[doc(no_inline)]
pub use generic_const_mappings::{Const, ToUInt, U};
/// A potential output from `Cmp`, this is the type equivalent to the enum variant
/// `core::cmp::Ordering::Greater`.
#[derive(Eq, PartialEq, Ord, PartialOrd, Clone, Copy, Hash, Debug, Default)]
#[cfg_attr(feature = "scale_info", derive(scale_info::TypeInfo))]
pub struct Greater;
/// A potential output from `Cmp`, this is the type equivalent to the enum variant
/// `core::cmp::Ordering::Less`.
#[derive(Eq, PartialEq, Ord, PartialOrd, Clone, Copy, Hash, Debug, Default)]
#[cfg_attr(feature = "scale_info", derive(scale_info::TypeInfo))]
pub struct Less;
/// A potential output from `Cmp`, this is the type equivalent to the enum variant
/// `core::cmp::Ordering::Equal`.
#[derive(Eq, PartialEq, Ord, PartialOrd, Clone, Copy, Hash, Debug, Default)]
#[cfg_attr(feature = "scale_info", derive(scale_info::TypeInfo))]
pub struct Equal;
/// Returns `core::cmp::Ordering::Greater`
impl Ord for Greater {
#[inline]
fn to_ordering() -> Ordering {
Ordering::Greater
}
}
/// Returns `core::cmp::Ordering::Less`
impl Ord for Less {
#[inline]
fn to_ordering() -> Ordering {
Ordering::Less
}
}
/// Returns `core::cmp::Ordering::Equal`
impl Ord for Equal {
#[inline]
fn to_ordering() -> Ordering {
Ordering::Equal
}
}
/// Asserts that two types are the same.
#[macro_export]
macro_rules! assert_type_eq {
($a:ty, $b:ty) => {
const _: core::marker::PhantomData<<$a as $crate::Same<$b>>::Output> =
core::marker::PhantomData;
};
}
/// Asserts that a type is `True`, aka `B1`.
#[macro_export]
macro_rules! assert_type {
($a:ty) => {
const _: core::marker::PhantomData<<$a as $crate::Same<True>>::Output> =
core::marker::PhantomData;
};
}
mod sealed {
use crate::{
ATerm, Bit, Equal, Greater, Less, NInt, NonZero, PInt, TArr, UInt, UTerm, Unsigned, B0, B1,
Z0,
};
pub trait Sealed {}
impl Sealed for B0 {}
impl Sealed for B1 {}
impl Sealed for UTerm {}
impl<U: Unsigned, B: Bit> Sealed for UInt<U, B> {}
impl Sealed for Z0 {}
impl<U: Unsigned + NonZero> Sealed for PInt<U> {}
impl<U: Unsigned + NonZero> Sealed for NInt<U> {}
impl Sealed for Less {}
impl Sealed for Equal {}
impl Sealed for Greater {}
impl Sealed for ATerm {}
impl<V, A> Sealed for TArr<V, A> {}
}

189
vendor/typenum/src/marker_traits.rs vendored Normal file
View File

@@ -0,0 +1,189 @@
//! All of the **marker traits** used in typenum.
//!
//! Note that the definition here for marker traits is slightly different than
//! the conventional one -- we include traits with functions that convert a type
//! to the corresponding value, as well as associated constants that do the
//! same.
//!
//! For example, the `Integer` trait includes the function (among others) `fn
//! to_i32() -> i32` and the associated constant `I32` so that one can do this:
//!
//! ```
//! use typenum::{Integer, N42};
//!
//! assert_eq!(-42, N42::to_i32());
//! assert_eq!(-42, N42::I32);
//! ```
use crate::sealed::Sealed;
/// A **marker trait** to designate that a type is not zero. All number types in this
/// crate implement `NonZero` except `B0`, `U0`, and `Z0`.
pub trait NonZero: Sealed {}
/// A **marker trait** to designate that a type is zero. Only `B0`, `U0`, and `Z0`
/// implement this trait.
pub trait Zero: Sealed {}
/// A **Marker trait** for the types `Greater`, `Equal`, and `Less`.
pub trait Ord: Sealed {
#[allow(missing_docs)]
fn to_ordering() -> ::core::cmp::Ordering;
}
/// The **marker trait** for compile time bits.
pub trait Bit: Sealed + Copy + Default + 'static {
#[allow(missing_docs)]
const U8: u8;
#[allow(missing_docs)]
const BOOL: bool;
/// Instantiates a singleton representing this bit.
fn new() -> Self;
#[allow(missing_docs)]
fn to_u8() -> u8;
#[allow(missing_docs)]
fn to_bool() -> bool;
}
/// The **marker trait** for compile time unsigned integers.
///
/// # Example
/// ```rust
/// use typenum::{Unsigned, U3};
///
/// assert_eq!(U3::to_u32(), 3);
/// assert_eq!(U3::I32, 3);
/// ```
pub trait Unsigned: Sealed + Copy + Default + 'static {
#[allow(missing_docs)]
const U8: u8;
#[allow(missing_docs)]
const U16: u16;
#[allow(missing_docs)]
const U32: u32;
#[allow(missing_docs)]
const U64: u64;
#[cfg(feature = "i128")]
#[allow(missing_docs)]
const U128: u128;
#[allow(missing_docs)]
const USIZE: usize;
#[allow(missing_docs)]
const I8: i8;
#[allow(missing_docs)]
const I16: i16;
#[allow(missing_docs)]
const I32: i32;
#[allow(missing_docs)]
const I64: i64;
#[cfg(feature = "i128")]
#[allow(missing_docs)]
const I128: i128;
#[allow(missing_docs)]
const ISIZE: isize;
#[allow(missing_docs)]
fn to_u8() -> u8;
#[allow(missing_docs)]
fn to_u16() -> u16;
#[allow(missing_docs)]
fn to_u32() -> u32;
#[allow(missing_docs)]
fn to_u64() -> u64;
#[cfg(feature = "i128")]
#[allow(missing_docs)]
fn to_u128() -> u128;
#[allow(missing_docs)]
fn to_usize() -> usize;
#[allow(missing_docs)]
fn to_i8() -> i8;
#[allow(missing_docs)]
fn to_i16() -> i16;
#[allow(missing_docs)]
fn to_i32() -> i32;
#[allow(missing_docs)]
fn to_i64() -> i64;
#[cfg(feature = "i128")]
#[allow(missing_docs)]
fn to_i128() -> i128;
#[allow(missing_docs)]
fn to_isize() -> isize;
}
/// The **marker trait** for compile time signed integers.
///
/// # Example
/// ```rust
/// use typenum::{Integer, P3};
///
/// assert_eq!(P3::to_i32(), 3);
/// assert_eq!(P3::I32, 3);
/// ```
pub trait Integer: Sealed + Copy + Default + 'static {
#[allow(missing_docs)]
const I8: i8;
#[allow(missing_docs)]
const I16: i16;
#[allow(missing_docs)]
const I32: i32;
#[allow(missing_docs)]
const I64: i64;
#[cfg(feature = "i128")]
#[allow(missing_docs)]
const I128: i128;
#[allow(missing_docs)]
const ISIZE: isize;
#[allow(missing_docs)]
fn to_i8() -> i8;
#[allow(missing_docs)]
fn to_i16() -> i16;
#[allow(missing_docs)]
fn to_i32() -> i32;
#[allow(missing_docs)]
fn to_i64() -> i64;
#[cfg(feature = "i128")]
#[allow(missing_docs)]
fn to_i128() -> i128;
#[allow(missing_docs)]
fn to_isize() -> isize;
}
/// The **marker trait** for type-level arrays of type-level numbers.
///
/// Someday, it may contain an associated constant to produce a runtime array,
/// like the other marker traits here. However, that is blocked by [this
/// issue](https://github.com/rust-lang/rust/issues/44168).
pub trait TypeArray: Sealed {}
/// The **marker trait** for type-level numbers which are a power of two.
///
/// # Examples
///
/// Here's a working example:
///
/// ```rust
/// use typenum::{PowerOfTwo, P4, P8};
///
/// fn only_p2<P: PowerOfTwo>() {}
///
/// only_p2::<P4>();
/// only_p2::<P8>();
/// ```
///
/// Numbers which are not a power of two will fail to compile in this example:
///
/// ```rust,compile_fail
/// use typenum::{P9, P511, P1023, PowerOfTwo};
///
/// fn only_p2<P: PowerOfTwo>() { }
///
/// only_p2::<P9>();
/// only_p2::<P511>();
/// only_p2::<P1023>();
/// ```
pub trait PowerOfTwo: Sealed {}

115
vendor/typenum/src/operator_aliases.rs vendored Normal file
View File

@@ -0,0 +1,115 @@
//! Aliases for the type operators used in this crate.
//! Their purpose is to increase the ergonomics of performing operations on the types defined
//! here. For even more ergonomics, consider using the `op!` macro instead.
//!
//! For example, type `X` and type `Y` are the same here:
//!
//! ```rust
//! # #[macro_use] extern crate typenum;
//! use std::ops::Mul;
//! use typenum::{Prod, P5, P7};
//!
//! type X = <P7 as Mul<P5>>::Output;
//! type Y = Prod<P7, P5>;
//!
//! assert_type_eq!(X, Y);
//! ```
// Aliases!!!
use crate::type_operators::{
Abs, Cmp, FoldAdd, FoldMul, Gcd, Len, Logarithm2, Max, Min, PartialDiv, Pow, SquareRoot,
};
use core::ops::{Add, BitAnd, BitOr, BitXor, Div, Mul, Neg, Rem, Shl, Shr, Sub};
/// Alias for the associated type of `BitAnd`: `And<A, B> = <A as BitAnd<B>>::Output`
pub type And<A, B> = <A as BitAnd<B>>::Output;
/// Alias for the associated type of `BitOr`: `Or<A, B> = <A as BitOr<B>>::Output`
pub type Or<A, B> = <A as BitOr<B>>::Output;
/// Alias for the associated type of `BitXor`: `Xor<A, B> = <A as BitXor<B>>::Output`
pub type Xor<A, B> = <A as BitXor<B>>::Output;
/// Alias for the associated type of `Shl`: `Shleft<A, B> = <A as Shl<B>>::Output`
pub type Shleft<A, B> = <A as Shl<B>>::Output;
/// Alias for the associated type of `Shr`: `Shright<A, B> = <A as Shr<B>>::Output`
pub type Shright<A, B> = <A as Shr<B>>::Output;
/// Alias for the associated type of `Add`: `Sum<A, B> = <A as Add<B>>::Output`
pub type Sum<A, B> = <A as Add<B>>::Output;
/// Alias for the associated type of `Sub`: `Diff<A, B> = <A as Sub<B>>::Output`
pub type Diff<A, B> = <A as Sub<B>>::Output;
/// Alias for the associated type of `Mul`: `Prod<A, B> = <A as Mul<B>>::Output`
pub type Prod<A, B> = <A as Mul<B>>::Output;
/// Alias for the associated type of `Div`: `Quot<A, B> = <A as Div<B>>::Output`
pub type Quot<A, B> = <A as Div<B>>::Output;
/// Alias for the associated type of `Rem`: `Mod<A, B> = <A as Rem<B>>::Output`
pub type Mod<A, B> = <A as Rem<B>>::Output;
/// Alias for the associated type of
/// `PartialDiv`: `PartialQuot<A, B> = <A as PartialDiv<B>>::Output`
pub type PartialQuot<A, B> = <A as PartialDiv<B>>::Output;
/// Alias for the associated type of `Neg`: `Negate<A> = <A as Neg>::Output`
pub type Negate<A> = <A as Neg>::Output;
/// Alias for the associated type of `Abs`: `AbsVal<A> = <A as Abs>::Output`
pub type AbsVal<A> = <A as Abs>::Output;
/// Alias for the associated type of `Pow`: `Exp<A, B> = <A as Pow<B>>::Output`
pub type Exp<A, B> = <A as Pow<B>>::Output;
/// Alias for the associated type of `Gcd`: `Gcf<A, B> = <A as Gcd<B>>::Output>`
pub type Gcf<A, B> = <A as Gcd<B>>::Output;
/// Alias to make it easy to add 1: `Add1<A> = <A as Add<B1>>::Output`
pub type Add1<A> = <A as Add<crate::bit::B1>>::Output;
/// Alias to make it easy to subtract 1: `Sub1<A> = <A as Sub<B1>>::Output`
pub type Sub1<A> = <A as Sub<crate::bit::B1>>::Output;
/// Alias to make it easy to multiply by 2. `Double<A> = Shleft<A, B1>`
pub type Double<A> = Shleft<A, crate::bit::B1>;
/// Alias to make it easy to square. `Square<A> = <A as Mul<A>>::Output`
pub type Square<A> = <A as Mul>::Output;
/// Alias to make it easy to cube. `Cube<A> = <Square<A> as Mul<A>>::Output`
pub type Cube<A> = <Square<A> as Mul<A>>::Output;
/// Alias for the associated type of `SquareRoot`: `Sqrt<A> = <A as SquareRoot>::Output`
pub type Sqrt<A> = <A as SquareRoot>::Output;
/// Alias for the associated type of `Cmp`: `Compare<A, B> = <A as Cmp<B>>::Output`
pub type Compare<A, B> = <A as Cmp<B>>::Output;
/// Alias for the associated type of `Len`: `Length<A> = <A as Len>::Output`
pub type Length<T> = <T as Len>::Output;
/// Alias for the associated type of `FoldAdd`: `FoldSum<A> = <A as FoldAdd>::Output`
pub type FoldSum<A> = <A as FoldAdd>::Output;
/// Alias for the associated type of `FoldMul`: `FoldProd<A> = <A as FoldMul>::Output`
pub type FoldProd<A> = <A as FoldMul>::Output;
/// Alias for the associated type of `Min`: `Minimum<A, B> = <A as Min<B>>::Output`
pub type Minimum<A, B> = <A as Min<B>>::Output;
/// Alias for the associated type of `Max`: `Maximum<A, B> = <A as Max<B>>::Output`
pub type Maximum<A, B> = <A as Max<B>>::Output;
use crate::type_operators::{
IsEqual, IsGreater, IsGreaterOrEqual, IsLess, IsLessOrEqual, IsNotEqual,
};
/// Alias for the associated type of `IsLess`: `Le<A, B> = <A as IsLess<B>>::Output`
pub type Le<A, B> = <A as IsLess<B>>::Output;
/// Alias for the associated type of `IsEqual`: `Eq<A, B> = <A as IsEqual<B>>::Output`
pub type Eq<A, B> = <A as IsEqual<B>>::Output;
/// Alias for the associated type of `IsGreater`: `Gr<A, B> = <A as IsGreater<B>>::Output`
pub type Gr<A, B> = <A as IsGreater<B>>::Output;
/// Alias for the associated type of `IsGreaterOrEqual`:
/// `GrEq<A, B> = <A as IsGreaterOrEqual<B>>::Output`
pub type GrEq<A, B> = <A as IsGreaterOrEqual<B>>::Output;
/// Alias for the associated type of `IsLessOrEqual`: `LeEq<A, B> = <A as IsLessOrEqual<B>>::Output`
pub type LeEq<A, B> = <A as IsLessOrEqual<B>>::Output;
/// Alias for the associated type of `IsNotEqual`: `NotEq<A, B> = <A as IsNotEqual<B>>::Output`
pub type NotEq<A, B> = <A as IsNotEqual<B>>::Output;
/// Alias for the associated type of `Logarithm2`: `Log2<A> = <A as Logarithm2>::Output`
pub type Log2<A> = <A as Logarithm2>::Output;

592
vendor/typenum/src/private.rs vendored Normal file
View File

@@ -0,0 +1,592 @@
//! **Ignore me!** This module is for things that are conceptually private but that must
//! be made public for typenum to work correctly.
//!
//! Unless you are working on typenum itself, **there is no need to view anything here**.
//!
//! Certainly don't implement any of the traits here for anything.
//!
//!
//! Just look away.
//!
//!
//! Loooooooooooooooooooooooooooooooooook awaaaaaaaaaaaayyyyyyyyyyyyyyyyyyyyyyyyyyyyy...
//!
//!
//! If you do manage to find something of use in here, please let me know. If you can make a
//! compelling case, it may be moved out of __private.
//!
//! Note: Aliases for private type operators will all be named simply that operator followed
//! by an abbreviated name of its associated type.
#![doc(hidden)]
use crate::{
bit::{Bit, B0, B1},
uint::{UInt, UTerm, Unsigned},
};
/// A marker for restricting a method on a public trait to internal use only.
pub(crate) enum Internal {}
pub trait InternalMarker {}
impl InternalMarker for Internal {}
/// Convenience trait. Calls `Invert` -> `TrimTrailingZeros` -> `Invert`
pub trait Trim {
type Output;
fn trim(self) -> Self::Output;
}
pub type TrimOut<A> = <A as Trim>::Output;
/// Gets rid of all zeros until it hits a one.
// ONLY IMPLEMENT FOR INVERTED NUMBERS!
pub trait TrimTrailingZeros {
type Output;
fn trim_trailing_zeros(self) -> Self::Output;
}
pub type TrimTrailingZerosOut<A> = <A as TrimTrailingZeros>::Output;
/// Converts between standard numbers and inverted ones that have the most significant
/// digit on the outside.
pub trait Invert {
type Output;
fn invert(self) -> Self::Output;
}
pub type InvertOut<A> = <A as Invert>::Output;
/// Doubly private! Called by invert to make the magic happen once its done the first step.
/// The Rhs is what we've got so far.
pub trait PrivateInvert<Rhs> {
type Output;
fn private_invert(self, rhs: Rhs) -> Self::Output;
}
pub type PrivateInvertOut<A, Rhs> = <A as PrivateInvert<Rhs>>::Output;
/// Terminating character for `InvertedUInt`s
pub struct InvertedUTerm;
/// Inverted `UInt` (has most significant digit on the outside)
pub struct InvertedUInt<IU: InvertedUnsigned, B: Bit> {
msb: IU,
lsb: B,
}
/// Does the real anding for `UInt`s; `And` just calls this and then `Trim`.
pub trait PrivateAnd<Rhs = Self> {
type Output;
fn private_and(self, rhs: Rhs) -> Self::Output;
}
pub type PrivateAndOut<A, Rhs> = <A as PrivateAnd<Rhs>>::Output;
/// Does the real xoring for `UInt`s; `Xor` just calls this and then `Trim`.
pub trait PrivateXor<Rhs = Self> {
type Output;
fn private_xor(self, rhs: Rhs) -> Self::Output;
}
pub type PrivateXorOut<A, Rhs> = <A as PrivateXor<Rhs>>::Output;
/// Does the real subtraction for `UInt`s; `Sub` just calls this and then `Trim`.
pub trait PrivateSub<Rhs = Self> {
type Output;
fn private_sub(self, rhs: Rhs) -> Self::Output;
}
pub type PrivateSubOut<A, Rhs> = <A as PrivateSub<Rhs>>::Output;
/// Used for addition of signed integers; `C = P.cmp(N)`
/// Assumes `P = Self` is positive and `N` is negative
/// where `P` and `N` are both passed as unsigned integers
pub trait PrivateIntegerAdd<C, N> {
type Output;
fn private_integer_add(self, _: C, _: N) -> Self::Output;
}
pub type PrivateIntegerAddOut<P, C, N> = <P as PrivateIntegerAdd<C, N>>::Output;
pub trait PrivatePow<Y, N> {
type Output;
fn private_pow(self, _: Y, _: N) -> Self::Output;
}
pub type PrivatePowOut<A, Y, N> = <A as PrivatePow<Y, N>>::Output;
/// Performs `Shl` on `Lhs` so that `SizeOf(Lhs) = SizeOf(Rhs)`
/// Fails if `SizeOf(Lhs) > SizeOf(Rhs)`
pub trait ShiftDiff<Rhs> {
type Output;
}
pub type ShiftDiffOut<A, Rhs> = <A as ShiftDiff<Rhs>>::Output;
/// Gives `SizeOf(Lhs) - SizeOf(Rhs)`
pub trait BitDiff<Rhs> {
type Output;
}
pub type BitDiffOut<A, Rhs> = <A as BitDiff<Rhs>>::Output;
/// Inverted unsigned numbers
pub trait InvertedUnsigned {
fn to_u64() -> u64;
}
impl InvertedUnsigned for InvertedUTerm {
#[inline]
fn to_u64() -> u64 {
0
}
}
impl<IU: InvertedUnsigned, B: Bit> InvertedUnsigned for InvertedUInt<IU, B> {
#[inline]
fn to_u64() -> u64 {
u64::from(B::to_u8()) | IU::to_u64() << 1
}
}
impl Invert for UTerm {
type Output = InvertedUTerm;
#[inline]
fn invert(self) -> Self::Output {
InvertedUTerm
}
}
impl<U: Unsigned, B: Bit> Invert for UInt<U, B>
where
U: PrivateInvert<InvertedUInt<InvertedUTerm, B>>,
{
type Output = PrivateInvertOut<U, InvertedUInt<InvertedUTerm, B>>;
#[inline]
fn invert(self) -> Self::Output {
self.msb.private_invert(InvertedUInt {
msb: InvertedUTerm,
lsb: self.lsb,
})
}
}
impl<IU: InvertedUnsigned> PrivateInvert<IU> for UTerm {
type Output = IU;
#[inline]
fn private_invert(self, rhs: IU) -> Self::Output {
rhs
}
}
impl<IU: InvertedUnsigned, U: Unsigned, B: Bit> PrivateInvert<IU> for UInt<U, B>
where
U: PrivateInvert<InvertedUInt<IU, B>>,
{
type Output = PrivateInvertOut<U, InvertedUInt<IU, B>>;
#[inline]
fn private_invert(self, rhs: IU) -> Self::Output {
self.msb.private_invert(InvertedUInt {
msb: rhs,
lsb: self.lsb,
})
}
}
#[test]
fn test_inversion() {
type Test4 = <crate::consts::U4 as Invert>::Output;
type Test5 = <crate::consts::U5 as Invert>::Output;
type Test12 = <crate::consts::U12 as Invert>::Output;
type Test16 = <crate::consts::U16 as Invert>::Output;
assert_eq!(1, <Test4 as InvertedUnsigned>::to_u64());
assert_eq!(5, <Test5 as InvertedUnsigned>::to_u64());
assert_eq!(3, <Test12 as InvertedUnsigned>::to_u64());
assert_eq!(1, <Test16 as InvertedUnsigned>::to_u64());
}
impl Invert for InvertedUTerm {
type Output = UTerm;
#[inline]
fn invert(self) -> Self::Output {
UTerm
}
}
impl<IU: InvertedUnsigned, B: Bit> Invert for InvertedUInt<IU, B>
where
IU: PrivateInvert<UInt<UTerm, B>>,
{
type Output = <IU as PrivateInvert<UInt<UTerm, B>>>::Output;
#[inline]
fn invert(self) -> Self::Output {
self.msb.private_invert(UInt {
msb: UTerm,
lsb: self.lsb,
})
}
}
impl<U: Unsigned> PrivateInvert<U> for InvertedUTerm {
type Output = U;
#[inline]
fn private_invert(self, rhs: U) -> Self::Output {
rhs
}
}
impl<U: Unsigned, IU: InvertedUnsigned, B: Bit> PrivateInvert<U> for InvertedUInt<IU, B>
where
IU: PrivateInvert<UInt<U, B>>,
{
type Output = <IU as PrivateInvert<UInt<U, B>>>::Output;
#[inline]
fn private_invert(self, rhs: U) -> Self::Output {
self.msb.private_invert(UInt {
msb: rhs,
lsb: self.lsb,
})
}
}
#[test]
fn test_double_inversion() {
type Test4 = <<crate::consts::U4 as Invert>::Output as Invert>::Output;
type Test5 = <<crate::consts::U5 as Invert>::Output as Invert>::Output;
type Test12 = <<crate::consts::U12 as Invert>::Output as Invert>::Output;
type Test16 = <<crate::consts::U16 as Invert>::Output as Invert>::Output;
assert_eq!(4, <Test4 as Unsigned>::to_u64());
assert_eq!(5, <Test5 as Unsigned>::to_u64());
assert_eq!(12, <Test12 as Unsigned>::to_u64());
assert_eq!(16, <Test16 as Unsigned>::to_u64());
}
impl TrimTrailingZeros for InvertedUTerm {
type Output = InvertedUTerm;
#[inline]
fn trim_trailing_zeros(self) -> Self::Output {
InvertedUTerm
}
}
impl<IU: InvertedUnsigned> TrimTrailingZeros for InvertedUInt<IU, B1> {
type Output = Self;
#[inline]
fn trim_trailing_zeros(self) -> Self::Output {
self
}
}
impl<IU: InvertedUnsigned> TrimTrailingZeros for InvertedUInt<IU, B0>
where
IU: TrimTrailingZeros,
{
type Output = <IU as TrimTrailingZeros>::Output;
#[inline]
fn trim_trailing_zeros(self) -> Self::Output {
self.msb.trim_trailing_zeros()
}
}
impl<U: Unsigned> Trim for U
where
U: Invert,
<U as Invert>::Output: TrimTrailingZeros,
<<U as Invert>::Output as TrimTrailingZeros>::Output: Invert,
{
type Output = <<<U as Invert>::Output as TrimTrailingZeros>::Output as Invert>::Output;
#[inline]
fn trim(self) -> Self::Output {
self.invert().trim_trailing_zeros().invert()
}
}
// Note: Trimming is tested when we do subtraction.
pub trait PrivateCmp<Rhs, SoFar> {
type Output;
fn private_cmp(&self, _: &Rhs, _: SoFar) -> Self::Output;
}
pub type PrivateCmpOut<A, Rhs, SoFar> = <A as PrivateCmp<Rhs, SoFar>>::Output;
// Set Bit
pub trait PrivateSetBit<I, B> {
type Output;
fn private_set_bit(self, _: I, _: B) -> Self::Output;
}
pub type PrivateSetBitOut<N, I, B> = <N as PrivateSetBit<I, B>>::Output;
// Div
pub trait PrivateDiv<N, D, Q, R, I> {
type Quotient;
type Remainder;
fn private_div_quotient(self, _: N, _: D, _: Q, _: R, _: I) -> Self::Quotient;
fn private_div_remainder(self, _: N, _: D, _: Q, _: R, _: I) -> Self::Remainder;
}
pub type PrivateDivQuot<N, D, Q, R, I> = <() as PrivateDiv<N, D, Q, R, I>>::Quotient;
pub type PrivateDivRem<N, D, Q, R, I> = <() as PrivateDiv<N, D, Q, R, I>>::Remainder;
pub trait PrivateDivIf<N, D, Q, R, I, RcmpD> {
type Quotient;
type Remainder;
fn private_div_if_quotient(self, _: N, _: D, _: Q, _: R, _: I, _: RcmpD) -> Self::Quotient;
fn private_div_if_remainder(self, _: N, _: D, _: Q, _: R, _: I, _: RcmpD) -> Self::Remainder;
}
pub type PrivateDivIfQuot<N, D, Q, R, I, RcmpD> =
<() as PrivateDivIf<N, D, Q, R, I, RcmpD>>::Quotient;
pub type PrivateDivIfRem<N, D, Q, R, I, RcmpD> =
<() as PrivateDivIf<N, D, Q, R, I, RcmpD>>::Remainder;
// Div for signed ints
pub trait PrivateDivInt<C, Divisor> {
type Output;
fn private_div_int(self, _: C, _: Divisor) -> Self::Output;
}
pub type PrivateDivIntOut<A, C, Divisor> = <A as PrivateDivInt<C, Divisor>>::Output;
pub trait PrivateRem<URem, Divisor> {
type Output;
fn private_rem(self, _: URem, _: Divisor) -> Self::Output;
}
pub type PrivateRemOut<A, URem, Divisor> = <A as PrivateRem<URem, Divisor>>::Output;
// min max
pub trait PrivateMin<Rhs, CmpResult> {
type Output;
fn private_min(self, rhs: Rhs) -> Self::Output;
}
pub type PrivateMinOut<A, B, CmpResult> = <A as PrivateMin<B, CmpResult>>::Output;
pub trait PrivateMax<Rhs, CmpResult> {
type Output;
fn private_max(self, rhs: Rhs) -> Self::Output;
}
pub type PrivateMaxOut<A, B, CmpResult> = <A as PrivateMax<B, CmpResult>>::Output;
// Comparisons
use crate::{Equal, False, Greater, Less, True};
pub trait IsLessPrivate<Rhs, Cmp> {
type Output: Bit;
#[allow(clippy::wrong_self_convention)]
fn is_less_private(self, _: Rhs, _: Cmp) -> Self::Output;
}
impl<A, B> IsLessPrivate<B, Less> for A {
type Output = True;
#[inline]
fn is_less_private(self, _: B, _: Less) -> Self::Output {
B1
}
}
impl<A, B> IsLessPrivate<B, Equal> for A {
type Output = False;
#[inline]
fn is_less_private(self, _: B, _: Equal) -> Self::Output {
B0
}
}
impl<A, B> IsLessPrivate<B, Greater> for A {
type Output = False;
#[inline]
fn is_less_private(self, _: B, _: Greater) -> Self::Output {
B0
}
}
pub trait IsEqualPrivate<Rhs, Cmp> {
type Output: Bit;
#[allow(clippy::wrong_self_convention)]
fn is_equal_private(self, _: Rhs, _: Cmp) -> Self::Output;
}
impl<A, B> IsEqualPrivate<B, Less> for A {
type Output = False;
#[inline]
fn is_equal_private(self, _: B, _: Less) -> Self::Output {
B0
}
}
impl<A, B> IsEqualPrivate<B, Equal> for A {
type Output = True;
#[inline]
fn is_equal_private(self, _: B, _: Equal) -> Self::Output {
B1
}
}
impl<A, B> IsEqualPrivate<B, Greater> for A {
type Output = False;
#[inline]
fn is_equal_private(self, _: B, _: Greater) -> Self::Output {
B0
}
}
pub trait IsGreaterPrivate<Rhs, Cmp> {
type Output: Bit;
#[allow(clippy::wrong_self_convention)]
fn is_greater_private(self, _: Rhs, _: Cmp) -> Self::Output;
}
impl<A, B> IsGreaterPrivate<B, Less> for A {
type Output = False;
#[inline]
fn is_greater_private(self, _: B, _: Less) -> Self::Output {
B0
}
}
impl<A, B> IsGreaterPrivate<B, Equal> for A {
type Output = False;
#[inline]
fn is_greater_private(self, _: B, _: Equal) -> Self::Output {
B0
}
}
impl<A, B> IsGreaterPrivate<B, Greater> for A {
type Output = True;
#[inline]
fn is_greater_private(self, _: B, _: Greater) -> Self::Output {
B1
}
}
pub trait IsLessOrEqualPrivate<Rhs, Cmp> {
type Output: Bit;
#[allow(clippy::wrong_self_convention)]
fn is_less_or_equal_private(self, _: Rhs, _: Cmp) -> Self::Output;
}
impl<A, B> IsLessOrEqualPrivate<B, Less> for A {
type Output = True;
#[inline]
fn is_less_or_equal_private(self, _: B, _: Less) -> Self::Output {
B1
}
}
impl<A, B> IsLessOrEqualPrivate<B, Equal> for A {
type Output = True;
#[inline]
fn is_less_or_equal_private(self, _: B, _: Equal) -> Self::Output {
B1
}
}
impl<A, B> IsLessOrEqualPrivate<B, Greater> for A {
type Output = False;
#[inline]
fn is_less_or_equal_private(self, _: B, _: Greater) -> Self::Output {
B0
}
}
pub trait IsNotEqualPrivate<Rhs, Cmp> {
type Output: Bit;
#[allow(clippy::wrong_self_convention)]
fn is_not_equal_private(self, _: Rhs, _: Cmp) -> Self::Output;
}
impl<A, B> IsNotEqualPrivate<B, Less> for A {
type Output = True;
#[inline]
fn is_not_equal_private(self, _: B, _: Less) -> Self::Output {
B1
}
}
impl<A, B> IsNotEqualPrivate<B, Equal> for A {
type Output = False;
#[inline]
fn is_not_equal_private(self, _: B, _: Equal) -> Self::Output {
B0
}
}
impl<A, B> IsNotEqualPrivate<B, Greater> for A {
type Output = True;
#[inline]
fn is_not_equal_private(self, _: B, _: Greater) -> Self::Output {
B1
}
}
pub trait IsGreaterOrEqualPrivate<Rhs, Cmp> {
type Output: Bit;
#[allow(clippy::wrong_self_convention)]
fn is_greater_or_equal_private(self, _: Rhs, _: Cmp) -> Self::Output;
}
impl<A, B> IsGreaterOrEqualPrivate<B, Less> for A {
type Output = False;
#[inline]
fn is_greater_or_equal_private(self, _: B, _: Less) -> Self::Output {
B0
}
}
impl<A, B> IsGreaterOrEqualPrivate<B, Equal> for A {
type Output = True;
#[inline]
fn is_greater_or_equal_private(self, _: B, _: Equal) -> Self::Output {
B1
}
}
impl<A, B> IsGreaterOrEqualPrivate<B, Greater> for A {
type Output = True;
#[inline]
fn is_greater_or_equal_private(self, _: B, _: Greater) -> Self::Output {
B1
}
}
pub trait PrivateSquareRoot {
type Output;
}
pub trait PrivateLogarithm2 {
type Output;
}

626
vendor/typenum/src/type_operators.rs vendored Normal file
View File

@@ -0,0 +1,626 @@
//! Useful **type operators** that are not defined in `core::ops`.
use crate::{
private::{Internal, InternalMarker},
Bit, NInt, NonZero, PInt, UInt, UTerm, Unsigned, Z0,
};
/// A **type operator** that ensures that `Rhs` is the same as `Self`, it is mainly useful
/// for writing macros that can take arbitrary binary or unary operators.
///
/// `Same` is implemented generically for all types; it should never need to be implemented
/// for anything else.
///
/// Note that Rust lazily evaluates types, so this will only fail for two different types if
/// the `Output` is used.
///
/// # Example
/// ```rust
/// use typenum::{Same, Unsigned, U4, U5};
///
/// assert_eq!(<U5 as Same<U5>>::Output::to_u32(), 5);
///
/// // Only an error if we use it:
/// # #[allow(dead_code)]
/// type Undefined = <U5 as Same<U4>>::Output;
/// // Compiler error:
/// // Undefined::to_u32();
/// ```
pub trait Same<Rhs = Self> {
/// Should always be `Self`
type Output;
}
impl<T> Same<T> for T {
type Output = T;
}
/// A **type operator** that returns the absolute value.
///
/// # Example
/// ```rust
/// use typenum::{Abs, Integer, N5};
///
/// assert_eq!(<N5 as Abs>::Output::to_i32(), 5);
/// ```
pub trait Abs {
/// The absolute value.
type Output;
}
impl Abs for Z0 {
type Output = Z0;
}
impl<U: Unsigned + NonZero> Abs for PInt<U> {
type Output = Self;
}
impl<U: Unsigned + NonZero> Abs for NInt<U> {
type Output = PInt<U>;
}
/// A **type operator** that provides exponentiation by repeated squaring.
///
/// # Example
/// ```rust
/// use typenum::{Integer, Pow, N3, P3};
///
/// assert_eq!(<N3 as Pow<P3>>::Output::to_i32(), -27);
/// ```
pub trait Pow<Exp> {
/// The result of the exponentiation.
type Output;
/// This function isn't used in this crate, but may be useful for others.
/// It is implemented for primitives.
///
/// # Example
/// ```rust
/// use typenum::{Pow, U3};
///
/// let a = 7u32.powi(U3::new());
/// let b = 7u32.pow(3);
/// assert_eq!(a, b);
///
/// let x = 3.0.powi(U3::new());
/// let y = 27.0;
/// assert_eq!(x, y);
/// ```
fn powi(self, exp: Exp) -> Self::Output;
}
macro_rules! impl_pow_f {
($t:ty) => {
impl Pow<UTerm> for $t {
type Output = $t;
#[inline]
fn powi(self, _: UTerm) -> Self::Output {
1.0
}
}
impl<U: Unsigned, B: Bit> Pow<UInt<U, B>> for $t {
type Output = $t;
// powi is unstable in core, so we have to write this function ourselves.
// copied from num::pow::pow
#[inline]
fn powi(self, _: UInt<U, B>) -> Self::Output {
let mut exp = <UInt<U, B> as Unsigned>::to_u32();
let mut base = self;
if exp == 0 {
return 1.0;
}
while exp & 1 == 0 {
base *= base;
exp >>= 1;
}
if exp == 1 {
return base;
}
let mut acc = base.clone();
while exp > 1 {
exp >>= 1;
base *= base;
if exp & 1 == 1 {
acc *= base.clone();
}
}
acc
}
}
impl Pow<Z0> for $t {
type Output = $t;
#[inline]
fn powi(self, _: Z0) -> Self::Output {
1.0
}
}
impl<U: Unsigned + NonZero> Pow<PInt<U>> for $t {
type Output = $t;
// powi is unstable in core, so we have to write this function ourselves.
// copied from num::pow::pow
#[inline]
fn powi(self, _: PInt<U>) -> Self::Output {
let mut exp = U::to_u32();
let mut base = self;
if exp == 0 {
return 1.0;
}
while exp & 1 == 0 {
base *= base;
exp >>= 1;
}
if exp == 1 {
return base;
}
let mut acc = base.clone();
while exp > 1 {
exp >>= 1;
base *= base;
if exp & 1 == 1 {
acc *= base.clone();
}
}
acc
}
}
impl<U: Unsigned + NonZero> Pow<NInt<U>> for $t {
type Output = $t;
#[inline]
fn powi(self, _: NInt<U>) -> Self::Output {
<$t as Pow<PInt<U>>>::powi(self, PInt::new()).recip()
}
}
};
}
impl_pow_f!(f32);
impl_pow_f!(f64);
macro_rules! impl_pow_i {
() => ();
($(#[$meta:meta])* $t: ty $(, $tail:tt)*) => (
$(#[$meta])*
impl Pow<UTerm> for $t {
type Output = $t;
#[inline]
fn powi(self, _: UTerm) -> Self::Output {
1
}
}
$(#[$meta])*
impl<U: Unsigned, B: Bit> Pow<UInt<U, B>> for $t {
type Output = $t;
#[inline]
fn powi(self, _: UInt<U, B>) -> Self::Output {
self.pow(<UInt<U, B> as Unsigned>::to_u32())
}
}
$(#[$meta])*
impl Pow<Z0> for $t {
type Output = $t;
#[inline]
fn powi(self, _: Z0) -> Self::Output {
1
}
}
$(#[$meta])*
impl<U: Unsigned + NonZero> Pow<PInt<U>> for $t {
type Output = $t;
#[inline]
fn powi(self, _: PInt<U>) -> Self::Output {
self.pow(U::to_u32())
}
}
impl_pow_i!($($tail),*);
);
}
impl_pow_i!(u8, u16, u32, u64, usize, i8, i16, i32, i64, isize);
#[cfg(feature = "i128")]
impl_pow_i!(
#[cfg_attr(docsrs, doc(cfg(feature = "i128")))]
u128,
i128
);
#[test]
fn pow_test() {
use crate::consts::*;
let z0 = Z0::new();
let p3 = P3::new();
let u0 = U0::new();
let u3 = U3::new();
let n3 = N3::new();
macro_rules! check {
($x:ident) => {
assert_eq!($x.powi(z0), 1);
assert_eq!($x.powi(u0), 1);
assert_eq!($x.powi(p3), $x * $x * $x);
assert_eq!($x.powi(u3), $x * $x * $x);
};
($x:ident, $f:ident) => {
assert!((<$f as Pow<Z0>>::powi(*$x, z0) - 1.0).abs() < ::core::$f::EPSILON);
assert!((<$f as Pow<U0>>::powi(*$x, u0) - 1.0).abs() < ::core::$f::EPSILON);
assert!((<$f as Pow<P3>>::powi(*$x, p3) - $x * $x * $x).abs() < ::core::$f::EPSILON);
assert!((<$f as Pow<U3>>::powi(*$x, u3) - $x * $x * $x).abs() < ::core::$f::EPSILON);
if *$x == 0.0 {
assert!(<$f as Pow<N3>>::powi(*$x, n3).is_infinite());
} else {
assert!(
(<$f as Pow<N3>>::powi(*$x, n3) - 1. / $x / $x / $x).abs()
< ::core::$f::EPSILON
);
}
};
}
for x in &[0i8, -3, 2] {
check!(x);
}
for x in &[0u8, 1, 5] {
check!(x);
}
for x in &[0usize, 1, 5, 40] {
check!(x);
}
for x in &[0isize, 1, 2, -30, -22, 48] {
check!(x);
}
for x in &[0.0f32, 2.2, -3.5, 378.223] {
check!(x, f32);
}
for x in &[0.0f64, 2.2, -3.5, -2387.2, 234.22] {
check!(x, f64);
}
}
/// A **type operator** for comparing `Self` and `Rhs`. It provides a similar functionality to
/// the function
/// [`core::cmp::Ord::cmp`](https://doc.rust-lang.org/nightly/core/cmp/trait.Ord.html#tymethod.cmp)
/// but for types.
///
/// # Example
/// ```rust
/// use typenum::{Cmp, Ord, N3, P2, P5};
/// use std::cmp::Ordering;
///
/// assert_eq!(<P2 as Cmp<N3>>::Output::to_ordering(), Ordering::Greater);
/// assert_eq!(<P2 as Cmp<P2>>::Output::to_ordering(), Ordering::Equal);
/// assert_eq!(<P2 as Cmp<P5>>::Output::to_ordering(), Ordering::Less);
pub trait Cmp<Rhs = Self> {
/// The result of the comparison. It should only ever be one of `Greater`, `Less`, or `Equal`.
type Output;
#[doc(hidden)]
fn compare<IM: InternalMarker>(&self, _: &Rhs) -> Self::Output;
}
/// A **type operator** that gives the length of an `Array` or the number of bits in a `UInt`.
#[allow(clippy::len_without_is_empty)]
pub trait Len {
/// The length as a type-level unsigned integer.
type Output: crate::Unsigned;
/// This function isn't used in this crate, but may be useful for others.
fn len(&self) -> Self::Output;
}
/// A **type operator** that gives the sum of all elements of an `Array`.
pub trait FoldAdd {
/// The type of the result of the sum
type Output;
}
/// A **type operator** that gives the product of all elements of an `Array`.
pub trait FoldMul {
/// The type of the result of the product
type Output;
}
#[test]
fn fold_test() {
use crate::*;
assert_eq!(10, <FoldSum::<tarr![U2, U3, U5]>>::to_u32());
assert_eq!(30, <FoldProd::<tarr![U2, U3, U5]>>::to_u32());
}
/// Division as a partial function. This **type operator** performs division just as `Div`, but is
/// only defined when the result is an integer (i.e. there is no remainder).
pub trait PartialDiv<Rhs = Self> {
/// The type of the result of the division
type Output;
/// Method for performing the division
fn partial_div(self, _: Rhs) -> Self::Output;
}
/// A **type operator** that returns the minimum of `Self` and `Rhs`.
pub trait Min<Rhs = Self> {
/// The type of the minimum of `Self` and `Rhs`
type Output;
/// Method returning the minimum
fn min(self, rhs: Rhs) -> Self::Output;
}
/// A **type operator** that returns the maximum of `Self` and `Rhs`.
pub trait Max<Rhs = Self> {
/// The type of the maximum of `Self` and `Rhs`
type Output;
/// Method returning the maximum
fn max(self, rhs: Rhs) -> Self::Output;
}
use crate::Compare;
/// A **type operator** that returns `True` if `Self < Rhs`, otherwise returns `False`.
pub trait IsLess<Rhs = Self> {
/// The type representing either `True` or `False`
type Output: Bit;
/// Method returning `True` or `False`.
#[allow(clippy::wrong_self_convention)]
fn is_less(self, rhs: Rhs) -> Self::Output;
}
use crate::private::IsLessPrivate;
impl<A, B> IsLess<B> for A
where
A: Cmp<B> + IsLessPrivate<B, Compare<A, B>>,
{
type Output = <A as IsLessPrivate<B, Compare<A, B>>>::Output;
#[inline]
fn is_less(self, rhs: B) -> Self::Output {
let lhs_cmp_rhs = self.compare::<Internal>(&rhs);
self.is_less_private(rhs, lhs_cmp_rhs)
}
}
/// A **type operator** that returns `True` if `Self == Rhs`, otherwise returns `False`.
pub trait IsEqual<Rhs = Self> {
/// The type representing either `True` or `False`
type Output: Bit;
/// Method returning `True` or `False`.
#[allow(clippy::wrong_self_convention)]
fn is_equal(self, rhs: Rhs) -> Self::Output;
}
use crate::private::IsEqualPrivate;
impl<A, B> IsEqual<B> for A
where
A: Cmp<B> + IsEqualPrivate<B, Compare<A, B>>,
{
type Output = <A as IsEqualPrivate<B, Compare<A, B>>>::Output;
#[inline]
fn is_equal(self, rhs: B) -> Self::Output {
let lhs_cmp_rhs = self.compare::<Internal>(&rhs);
self.is_equal_private(rhs, lhs_cmp_rhs)
}
}
/// A **type operator** that returns `True` if `Self > Rhs`, otherwise returns `False`.
pub trait IsGreater<Rhs = Self> {
/// The type representing either `True` or `False`
type Output: Bit;
/// Method returning `True` or `False`.
#[allow(clippy::wrong_self_convention)]
fn is_greater(self, rhs: Rhs) -> Self::Output;
}
use crate::private::IsGreaterPrivate;
impl<A, B> IsGreater<B> for A
where
A: Cmp<B> + IsGreaterPrivate<B, Compare<A, B>>,
{
type Output = <A as IsGreaterPrivate<B, Compare<A, B>>>::Output;
#[inline]
fn is_greater(self, rhs: B) -> Self::Output {
let lhs_cmp_rhs = self.compare::<Internal>(&rhs);
self.is_greater_private(rhs, lhs_cmp_rhs)
}
}
/// A **type operator** that returns `True` if `Self <= Rhs`, otherwise returns `False`.
pub trait IsLessOrEqual<Rhs = Self> {
/// The type representing either `True` or `False`
type Output: Bit;
/// Method returning `True` or `False`.
#[allow(clippy::wrong_self_convention)]
fn is_less_or_equal(self, rhs: Rhs) -> Self::Output;
}
use crate::private::IsLessOrEqualPrivate;
impl<A, B> IsLessOrEqual<B> for A
where
A: Cmp<B> + IsLessOrEqualPrivate<B, Compare<A, B>>,
{
type Output = <A as IsLessOrEqualPrivate<B, Compare<A, B>>>::Output;
#[inline]
fn is_less_or_equal(self, rhs: B) -> Self::Output {
let lhs_cmp_rhs = self.compare::<Internal>(&rhs);
self.is_less_or_equal_private(rhs, lhs_cmp_rhs)
}
}
/// A **type operator** that returns `True` if `Self != Rhs`, otherwise returns `False`.
pub trait IsNotEqual<Rhs = Self> {
/// The type representing either `True` or `False`
type Output: Bit;
/// Method returning `True` or `False`.
#[allow(clippy::wrong_self_convention)]
fn is_not_equal(self, rhs: Rhs) -> Self::Output;
}
use crate::private::IsNotEqualPrivate;
impl<A, B> IsNotEqual<B> for A
where
A: Cmp<B> + IsNotEqualPrivate<B, Compare<A, B>>,
{
type Output = <A as IsNotEqualPrivate<B, Compare<A, B>>>::Output;
#[inline]
fn is_not_equal(self, rhs: B) -> Self::Output {
let lhs_cmp_rhs = self.compare::<Internal>(&rhs);
self.is_not_equal_private(rhs, lhs_cmp_rhs)
}
}
/// A **type operator** that returns `True` if `Self >= Rhs`, otherwise returns `False`.
pub trait IsGreaterOrEqual<Rhs = Self> {
/// The type representing either `True` or `False`
type Output: Bit;
/// Method returning `True` or `False`.
#[allow(clippy::wrong_self_convention)]
fn is_greater_or_equal(self, rhs: Rhs) -> Self::Output;
}
use crate::private::IsGreaterOrEqualPrivate;
impl<A, B> IsGreaterOrEqual<B> for A
where
A: Cmp<B> + IsGreaterOrEqualPrivate<B, Compare<A, B>>,
{
type Output = <A as IsGreaterOrEqualPrivate<B, Compare<A, B>>>::Output;
#[inline]
fn is_greater_or_equal(self, rhs: B) -> Self::Output {
let lhs_cmp_rhs = self.compare::<Internal>(&rhs);
self.is_greater_or_equal_private(rhs, lhs_cmp_rhs)
}
}
/**
A convenience macro for comparing type numbers. Use `op!` instead.
Due to the intricacies of the macro system, if the left-hand operand is more complex than a simple
`ident`, you must place a comma between it and the comparison sign.
For example, you can do `cmp!(P5 > P3)` or `cmp!(typenum::P5, > typenum::P3)` but not
`cmp!(typenum::P5 > typenum::P3)`.
The result of this comparison will always be one of `True` (aka `B1`) or `False` (aka `B0`).
# Example
```rust
#[macro_use] extern crate typenum;
use typenum::consts::*;
use typenum::Bit;
fn main() {
type Result = cmp!(P9 == op!(P1 + P2 * (P2 - N2)));
assert_eq!(Result::to_bool(), true);
}
```
*/
#[deprecated(since = "1.9.0", note = "use the `op!` macro instead")]
#[macro_export]
macro_rules! cmp {
($a:ident < $b:ty) => {
<$a as $crate::IsLess<$b>>::Output
};
($a:ty, < $b:ty) => {
<$a as $crate::IsLess<$b>>::Output
};
($a:ident == $b:ty) => {
<$a as $crate::IsEqual<$b>>::Output
};
($a:ty, == $b:ty) => {
<$a as $crate::IsEqual<$b>>::Output
};
($a:ident > $b:ty) => {
<$a as $crate::IsGreater<$b>>::Output
};
($a:ty, > $b:ty) => {
<$a as $crate::IsGreater<$b>>::Output
};
($a:ident <= $b:ty) => {
<$a as $crate::IsLessOrEqual<$b>>::Output
};
($a:ty, <= $b:ty) => {
<$a as $crate::IsLessOrEqual<$b>>::Output
};
($a:ident != $b:ty) => {
<$a as $crate::IsNotEqual<$b>>::Output
};
($a:ty, != $b:ty) => {
<$a as $crate::IsNotEqual<$b>>::Output
};
($a:ident >= $b:ty) => {
<$a as $crate::IsGreaterOrEqual<$b>>::Output
};
($a:ty, >= $b:ty) => {
<$a as $crate::IsGreaterOrEqual<$b>>::Output
};
}
/// A **type operator** for taking the integer square root of `Self`.
///
/// The integer square root of `n` is the largest integer `m` such
/// that `n >= m*m`. This definition is equivalent to truncating the
/// real-valued square root: `floor(real_sqrt(n))`.
pub trait SquareRoot {
/// The result of the integer square root.
type Output;
}
/// A **type operator** for taking the integer binary logarithm of `Self`.
///
/// The integer binary logarighm of `n` is the largest integer `m` such
/// that `n >= 2^m`. This definition is equivalent to truncating the
/// real-valued binary logarithm: `floor(log2(n))`.
pub trait Logarithm2 {
/// The result of the integer binary logarithm.
type Output;
}
/// A **type operator** that computes the [greatest common divisor][gcd] of `Self` and `Rhs`.
///
/// [gcd]: https://en.wikipedia.org/wiki/Greatest_common_divisor
///
/// # Example
///
/// ```rust
/// use typenum::{Gcd, Unsigned, U12, U8};
///
/// assert_eq!(<U12 as Gcd<U8>>::Output::to_i32(), 4);
/// ```
pub trait Gcd<Rhs> {
/// The greatest common divisor.
type Output;
}
/// A **type operator** for taking a concrete integer value from a type.
///
/// It returns arbitrary integer value without explicitly specifying the
/// type. It is useful when you pass the values to methods that accept
/// distinct types without runtime casting.
pub trait ToInt<T> {
/// Method returning the concrete value for the type.
fn to_int() -> T;
/// The concrete value for the type. Can be used in `const` contexts.
const INT: T;
}

2670
vendor/typenum/src/uint.rs vendored Normal file

File diff suppressed because it is too large Load Diff

2
vendor/typenum/tests/test.rs vendored Normal file
View File

@@ -0,0 +1,2 @@
#[cfg(test)]
include!(concat!(env!("OUT_DIR"), "/tests.rs"));