Bug 1806766 - Update typenum to 1.16.0. r=emilio,supply-chain-reviewers

Differential Revision: https://phabricator.services.mozilla.com/D165574
This commit is contained in:
Mike Hommey 2022-12-28 20:48:56 +00:00
Родитель 7ec9a6f94e
Коммит 3f12b1cfbc
12 изменённых файлов: 268 добавлений и 17 удалений

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

@ -5616,9 +5616,9 @@ checksum = "bfc9d8d4e8c94375df96d6ac01a18c263d3d529bc4a53a207580ae9bc30e87c1"
[[package]] [[package]]
name = "typenum" name = "typenum"
version = "1.15.0" version = "1.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987" checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba"
[[package]] [[package]]
name = "uluru" name = "uluru"

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

@ -1890,6 +1890,11 @@ who = "Lee Salzman <lsalzman@gmail.com>"
criteria = "safe-to-deploy" criteria = "safe-to-deploy"
version = "0.1.0" version = "0.1.0"
[[audits.typenum]]
who = "Mike Hommey <mh+mozilla@glandium.org>"
criteria = "safe-to-deploy"
delta = "1.15.0 -> 1.16.0"
[[audits.uluru]] [[audits.uluru]]
who = "Emilio Cobos Álvarez <emilio@crisal.io>" who = "Emilio Cobos Álvarez <emilio@crisal.io>"
criteria = "safe-to-deploy" criteria = "safe-to-deploy"

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

@ -1 +1 @@
{"files":{"CHANGELOG.md":"a9a7d1cecc4afa44451aa8c368ea51ca099c8076b22d1809c56eb8459dca78ac","Cargo.toml":"6de0aca94f7ce75d315ea069537f0eee37c62cb086fe5ec23a0e93653f171c4a","LICENSE":"db11fec9946737df39ca3898d9cd8c10ec6f6c3a884a6802b0ad0b81b4e8f23a","LICENSE-APACHE":"516b24e051bf5630880ebbd55c40a25ce9552ebaf8970a53e8976eb70e522406","LICENSE-MIT":"a825bd853ab71619a4923d7b4311221427848070ff44d990da39b0b274c1683f","README.md":"ab1dc7cd2ee48283b3a511463785da5dd3a93b387a26beb89185442eb66c7471","build/main.rs":"b4dd86261a70df757efa53f06ce7543a4dc9c51178b9b023c92069fddee97a29","build/op.rs":"f9fbdb6c907ebf0cf22071271ca3b5acac0db41db962c4211bf57eb21d12ee5c","build/tests.rs":"4e74a95412d9a7ad1dfba36cced27e3f723ab474a4b695d97c6adc30c5850d44","clippy.toml":"493258e6a4be8bbb66ecbc4236d8f4964f867d4bcddd5f13897aa655a206af7b","rustfmt.toml":"4953048a8d16fba8736c5cdb65ce418e462317a79793f16f79023f571f3fd5ce","src/array.rs":"d86f463e1f24a49073afc3ad875ea9b69ccfa85dad4c2738e022031c006f1087","src/bit.rs":"a658ddf3b93db9eeb8fb3eb659f67356de40d1bccf544672d650ae7be1d8e215","src/int.rs":"09dfbe75a2b2e31c7e567150002f56c9a22daa799fecbcc934a0f83644c15f8d","src/lib.rs":"31eb904ac8ebcb2730cfd32f093c39b2fe30d095c298d8ee7e4295556f548386","src/marker_traits.rs":"5a58d16edc16853b4b793a6b46068d926911273aa9dc57fd9dc64df77986b7dd","src/operator_aliases.rs":"c190f5bcf9f674c2f2bb56886a45ff548e5acb9320b406cbc45204ef3bac46d5","src/private.rs":"e2ab0e29eacdedfe4182aa0567ac8e9cb53680dc04e1d75e197321b4e1446111","src/type_operators.rs":"a9ea16c765254e40f958f512b7a6899e6441e9105f3c8f9590170a984d966cf6","src/uint.rs":"bc816d78c8e014e64e7e397a2d3776d7a69e6ef7b99d716b76dac7bcaf66d370","tests/test.rs":"92139fa86ffcacc1dff60e6fc36420c850d70dc814bd21dc18e87857553c6cea"},"package":"dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987"} {"files":{"CHANGELOG.md":"9990a2e222cad7eff8e8eec1e74a57e9aeecdb831e4a54208e7d5efd7b95432e","Cargo.toml":"e03aa2d8e8102aacf33c0dd58c8006bf7101b335d079d6b862870a471e488a3c","LICENSE":"db11fec9946737df39ca3898d9cd8c10ec6f6c3a884a6802b0ad0b81b4e8f23a","LICENSE-APACHE":"516b24e051bf5630880ebbd55c40a25ce9552ebaf8970a53e8976eb70e522406","LICENSE-MIT":"a825bd853ab71619a4923d7b4311221427848070ff44d990da39b0b274c1683f","README.md":"ab1dc7cd2ee48283b3a511463785da5dd3a93b387a26beb89185442eb66c7471","build/generic_const_mappings.rs":"b71d125b1a6e9696c5c0b24520c92aeca45fa14aa1189f1eee53b317d74de54a","build/main.rs":"006693936308cb1eca0768f94212ccdfe52951c79f64fd18f5c58124c1448f20","build/op.rs":"64ced5cb4016b28daa788e9f74713f1cb432af98c645f60641b90425f10741ec","build/tests.rs":"4e74a95412d9a7ad1dfba36cced27e3f723ab474a4b695d97c6adc30c5850d44","clippy.toml":"493258e6a4be8bbb66ecbc4236d8f4964f867d4bcddd5f13897aa655a206af7b","rustfmt.toml":"4953048a8d16fba8736c5cdb65ce418e462317a79793f16f79023f571f3fd5ce","src/array.rs":"d86f463e1f24a49073afc3ad875ea9b69ccfa85dad4c2738e022031c006f1087","src/bit.rs":"a658ddf3b93db9eeb8fb3eb659f67356de40d1bccf544672d650ae7be1d8e215","src/int.rs":"4adaadb711694426a6af1e7fbb54f33d668992ac0a674b77f0894a1a2213fda8","src/lib.rs":"c4368d0aedecd6e2dfe0d4716d55474a7f17e5bd7a4e59efb7a9e0494c9a25bc","src/marker_traits.rs":"5a58d16edc16853b4b793a6b46068d926911273aa9dc57fd9dc64df77986b7dd","src/operator_aliases.rs":"c190f5bcf9f674c2f2bb56886a45ff548e5acb9320b406cbc45204ef3bac46d5","src/private.rs":"e2ab0e29eacdedfe4182aa0567ac8e9cb53680dc04e1d75e197321b4e1446111","src/type_operators.rs":"cf04a1a4601b2d486e9e737130f1bff3e0a750fefe32b9f11c3bed0dad2c1a10","src/uint.rs":"a8872e9337e77158ec0d1cdf723dd8fefec22b58676e765098206f6cb24ba5db","tests/test.rs":"92139fa86ffcacc1dff60e6fc36420c850d70dc814bd21dc18e87857553c6cea"},"package":"497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba"}

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

@ -7,6 +7,10 @@ against this Rust version.
### Unreleased ### Unreleased
### 1.16.0 (2022-12-05)
- [added] `const INT` field to the `ToInt` trait.
- [added] `const-generics` field with `U<N>` mapping wher `N` is a const generic.
### 1.15.0 (2021-12-25) ### 1.15.0 (2021-12-25)
- [fixed] Cross-compilation issue due to doing math in build script. (PR #177) - [fixed] Cross-compilation issue due to doing math in build script. (PR #177)
- [added] New feature `scale_info` for using inside - [added] New feature `scale_info` for using inside

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

@ -11,11 +11,19 @@
[package] [package]
edition = "2018" edition = "2018"
rust-version = "1.37.0"
name = "typenum" name = "typenum"
version = "1.15.0" version = "1.16.0"
authors = ["Paho Lurie-Gregg <paho@paholg.com>", "Andre Bogus <bogusandre@gmail.com>"] authors = [
"Paho Lurie-Gregg <paho@paholg.com>",
"Andre Bogus <bogusandre@gmail.com>",
]
build = "build/main.rs" build = "build/main.rs"
description = "Typenum is a Rust library for type-level numbers evaluated at\n compile time. It currently supports bits, unsigned integers, and signed\n integers. It also provides a type-level array of type-level numbers, but its\n implementation is incomplete." 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" documentation = "https://docs.rs/typenum"
readme = "README.md" readme = "README.md"
categories = ["no-std"] categories = ["no-std"]
@ -24,12 +32,14 @@ repository = "https://github.com/paholg/typenum"
[lib] [lib]
name = "typenum" name = "typenum"
[dependencies.scale-info] [dependencies.scale-info]
version = "1.0" version = "1.0"
optional = true optional = true
default-features = false default-features = false
[features] [features]
const-generics = []
force_unix_path_separator = [] force_unix_path_separator = []
i128 = [] i128 = []
no_std = [] no_std = []

91
third_party/rust/typenum/build/generic_const_mappings.rs поставляемый Normal file
Просмотреть файл

@ -0,0 +1,91 @@
use super::*;
pub fn emit_impls() -> ::std::io::Result<()> {
let out_dir = ::std::env::var("OUT_DIR").unwrap();
let dest = ::std::path::Path::new(&out_dir).join("generic_const_mappings.rs");
println!(
"cargo:rustc-env=TYPENUM_BUILD_GENERIC_CONSTS={}",
dest.display()
);
let mut f = ::std::fs::File::create(&dest).unwrap();
#[allow(clippy::write_literal)]
write!(f, "{}", "\
#[cfg(doc)]
use generic_const_mappings::*;
/// Module with some `const`-generics-friendly definitions, to help bridge the gap
/// between those and `typenum` types.
///
/// - It requires the `const-generics` crate feature to be enabled.
///
/// The main type to use here is [`U`], although [`Const`] and [`ToUInt`] may be needed
/// in a generic context.
#[allow(warnings)] // script-generated code
pub mod generic_const_mappings {
use crate::*;
/// The main mapping from a generic `const: usize` to a [`UInt`]: [`U<N>`] is expected to work like [`UN`].
///
/// - It requires the `const-generics` crate feature to be enabled.
///
/// [`U<N>`]: `U`
/// [`UN`]: `U42`
///
/// # Example
///
/// ```rust
/// use typenum::*;
///
/// assert_type_eq!(U<42>, U42);
/// ```
///
/// This can even be used in a generic `const N: usize` context, provided the
/// genericity is guarded by a `where` clause:
///
/// ```rust
/// use typenum::*;
///
/// struct MyStruct<const N: usize>;
///
/// trait MyTrait { type AssocType; }
///
/// impl<const N: usize> MyTrait
/// for MyStruct<N>
/// where
/// Const<N> : ToUInt,
/// {
/// type AssocType = U<N>;
/// }
///
/// assert_type_eq!(<MyStruct<42> as MyTrait>::AssocType, U42);
/// ```
pub type U<const N: usize> = <Const<N> as ToUInt>::Output;
/// Used to allow the usage of [`U`] in a generic context.
pub struct Const<const N: usize>;
/// Used to allow the usage of [`U`] in a generic context.
pub trait ToUInt {
/// The [`UN`][`crate::U42`] type corresponding to `Self = Const<N>`.
type Output;
}
\
")?;
for uint in uints() {
write!(
f,
"
impl ToUInt for Const<{uint}> {{
type Output = U{uint};
}}
\
",
uint = uint,
)?;
}
write!(f, "}}")?;
f.flush()?;
Ok(())
}

27
third_party/rust/typenum/build/main.rs поставляемый
Просмотреть файл

@ -4,6 +4,8 @@ use std::fs::File;
use std::io::Write; use std::io::Write;
use std::path::Path; use std::path::Path;
#[cfg(feature = "const-generics")]
mod generic_const_mappings;
mod op; mod op;
mod tests; mod tests;
@ -75,21 +77,25 @@ pub fn gen_int(i: i64) -> IntCode {
)] )]
pub fn no_std() {} pub fn no_std() {}
// fixme: get a warning when testing without this const HIGHEST: u64 = 1024;
#[allow(dead_code)] fn uints() -> impl Iterator<Item = u64> {
fn main() {
let highest: u64 = 1024;
// Use hardcoded values to avoid issues with cross-compilation. // Use hardcoded values to avoid issues with cross-compilation.
// See https://github.com/paholg/typenum/issues/162 // See https://github.com/paholg/typenum/issues/162
let first2: u32 = 11; // (highest as f64).log(2.0).round() as u32 + 1; let first2: u32 = 11; // (highest as f64).log(2.0).round() as u32 + 1;
let first10: u32 = 4; // (highest as f64).log(10.0) as u32 + 1; let first10: u32 = 4; // (highest as f64).log(10.0) as u32 + 1;
let uints = (0..(highest + 1)) (0..(HIGHEST + 1))
.chain((first2..64).map(|i| 2u64.pow(i))) .chain((first2..64).map(|i| 2u64.pow(i)))
.chain((first10..20).map(|i| 10u64.pow(i))); .chain((first10..20).map(|i| 10u64.pow(i)))
}
// fixme: get a warning when testing without this
#[allow(dead_code)]
fn main() {
println!("cargo:rerun-if-changed=build/main.rs"); // Allow caching the generation if `src/*` files change.
let out_dir = env::var("OUT_DIR").unwrap(); let out_dir = env::var("OUT_DIR").unwrap();
let dest = Path::new(&out_dir).join("consts.rs"); let dest = Path::new(&out_dir).join("consts.rs");
#[cfg(not(feature = "force_unix_path_separator"))]
println!("cargo:rustc-env=TYPENUM_BUILD_CONSTS={}", dest.display()); println!("cargo:rustc-env=TYPENUM_BUILD_CONSTS={}", dest.display());
let mut f = File::create(&dest).unwrap(); let mut f = File::create(&dest).unwrap();
@ -162,11 +168,11 @@ pub mod consts {{
pub type True = B1; pub type True = B1;
pub type False = B0; pub type False = B0;
", ",
highest = highest highest = HIGHEST,
) )
.unwrap(); .unwrap();
for u in uints { for u in uints() {
writeln!(f, " pub type U{} = {};", u, gen_uint(u)).unwrap(); writeln!(f, " pub type U{} = {};", u, gen_uint(u)).unwrap();
if u <= ::std::i64::MAX as u64 && u != 0 { if u <= ::std::i64::MAX as u64 && u != 0 {
let i = u as i64; let i = u as i64;
@ -183,4 +189,7 @@ pub mod consts {{
tests::build_tests().unwrap(); tests::build_tests().unwrap();
op::write_op_macro().unwrap(); op::write_op_macro().unwrap();
#[cfg(feature = "const-generics")]
generic_const_mappings::emit_impls().unwrap();
} }

1
third_party/rust/typenum/build/op.rs поставляемый
Просмотреть файл

@ -18,6 +18,7 @@ struct Op {
pub fn write_op_macro() -> ::std::io::Result<()> { pub fn write_op_macro() -> ::std::io::Result<()> {
let out_dir = ::std::env::var("OUT_DIR").unwrap(); let out_dir = ::std::env::var("OUT_DIR").unwrap();
let dest = ::std::path::Path::new(&out_dir).join("op.rs"); let dest = ::std::path::Path::new(&out_dir).join("op.rs");
#[cfg(not(feature = "force_unix_path_separator"))]
println!("cargo:rustc-env=TYPENUM_BUILD_OP={}", dest.display()); println!("cargo:rustc-env=TYPENUM_BUILD_OP={}", dest.display());
let mut f = ::std::fs::File::create(&dest).unwrap(); let mut f = ::std::fs::File::create(&dest).unwrap();

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

@ -1187,6 +1187,7 @@ impl ToInt<i8> for Z0 {
fn to_int() -> i8 { fn to_int() -> i8 {
Self::I8 Self::I8
} }
const INT: i8 = Self::I8;
} }
impl ToInt<i16> for Z0 { impl ToInt<i16> for Z0 {
@ -1194,6 +1195,7 @@ impl ToInt<i16> for Z0 {
fn to_int() -> i16 { fn to_int() -> i16 {
Self::I16 Self::I16
} }
const INT: i16 = Self::I16;
} }
impl ToInt<i32> for Z0 { impl ToInt<i32> for Z0 {
@ -1201,6 +1203,7 @@ impl ToInt<i32> for Z0 {
fn to_int() -> i32 { fn to_int() -> i32 {
Self::I32 Self::I32
} }
const INT: i32 = Self::I32;
} }
impl ToInt<i64> for Z0 { impl ToInt<i64> for Z0 {
@ -1208,6 +1211,7 @@ impl ToInt<i64> for Z0 {
fn to_int() -> i64 { fn to_int() -> i64 {
Self::I64 Self::I64
} }
const INT: i64 = Self::I64;
} }
// negative numbers // negative numbers
@ -1220,6 +1224,7 @@ where
fn to_int() -> i8 { fn to_int() -> i8 {
Self::I8 Self::I8
} }
const INT: i8 = Self::I8;
} }
impl<U> ToInt<i16> for NInt<U> impl<U> ToInt<i16> for NInt<U>
@ -1230,6 +1235,7 @@ where
fn to_int() -> i16 { fn to_int() -> i16 {
Self::I16 Self::I16
} }
const INT: i16 = Self::I16;
} }
impl<U> ToInt<i32> for NInt<U> impl<U> ToInt<i32> for NInt<U>
@ -1240,6 +1246,7 @@ where
fn to_int() -> i32 { fn to_int() -> i32 {
Self::I32 Self::I32
} }
const INT: i32 = Self::I32;
} }
impl<U> ToInt<i64> for NInt<U> impl<U> ToInt<i64> for NInt<U>
@ -1250,6 +1257,7 @@ where
fn to_int() -> i64 { fn to_int() -> i64 {
Self::I64 Self::I64
} }
const INT: i64 = Self::I64;
} }
// positive numbers // positive numbers
@ -1262,6 +1270,7 @@ where
fn to_int() -> i8 { fn to_int() -> i8 {
Self::I8 Self::I8
} }
const INT: i8 = Self::I8;
} }
impl<U> ToInt<i16> for PInt<U> impl<U> ToInt<i16> for PInt<U>
@ -1272,6 +1281,7 @@ where
fn to_int() -> i16 { fn to_int() -> i16 {
Self::I16 Self::I16
} }
const INT: i16 = Self::I16;
} }
impl<U> ToInt<i32> for PInt<U> impl<U> ToInt<i32> for PInt<U>
@ -1282,6 +1292,7 @@ where
fn to_int() -> i32 { fn to_int() -> i32 {
Self::I32 Self::I32
} }
const INT: i32 = Self::I32;
} }
impl<U> ToInt<i64> for PInt<U> impl<U> ToInt<i64> for PInt<U>
@ -1292,6 +1303,7 @@ where
fn to_int() -> i64 { fn to_int() -> i64 {
Self::I64 Self::I64
} }
const INT: i64 = Self::I64;
} }
#[cfg(test)] #[cfg(test)]
@ -1316,6 +1328,15 @@ mod tests {
assert_eq!(-2_i8, N2::to_int()); assert_eq!(-2_i8, N2::to_int());
assert_eq!(-3_i8, N3::to_int()); assert_eq!(-3_i8, N3::to_int());
assert_eq!(-4_i8, N4::to_int()); assert_eq!(-4_i8, N4::to_int());
assert_eq!(0_i8, Z0::INT);
assert_eq!(1_i8, P1::INT);
assert_eq!(2_i8, P2::INT);
assert_eq!(3_i8, P3::INT);
assert_eq!(4_i8, P4::INT);
assert_eq!(-1_i8, N1::INT);
assert_eq!(-2_i8, N2::INT);
assert_eq!(-3_i8, N3::INT);
assert_eq!(-4_i8, N4::INT);
// i16 // i16
assert_eq!(0_i16, Z0::to_int()); assert_eq!(0_i16, Z0::to_int());
@ -1327,6 +1348,15 @@ mod tests {
assert_eq!(-2_i16, N2::to_int()); assert_eq!(-2_i16, N2::to_int());
assert_eq!(-3_i16, N3::to_int()); assert_eq!(-3_i16, N3::to_int());
assert_eq!(-4_i16, N4::to_int()); assert_eq!(-4_i16, N4::to_int());
assert_eq!(0_i16, Z0::INT);
assert_eq!(1_i16, P1::INT);
assert_eq!(2_i16, P2::INT);
assert_eq!(3_i16, P3::INT);
assert_eq!(4_i16, P4::INT);
assert_eq!(-1_i16, N1::INT);
assert_eq!(-2_i16, N2::INT);
assert_eq!(-3_i16, N3::INT);
assert_eq!(-4_i16, N4::INT);
// i32 // i32
assert_eq!(0_i32, Z0::to_int()); assert_eq!(0_i32, Z0::to_int());
@ -1338,6 +1368,15 @@ mod tests {
assert_eq!(-2_i32, N2::to_int()); assert_eq!(-2_i32, N2::to_int());
assert_eq!(-3_i32, N3::to_int()); assert_eq!(-3_i32, N3::to_int());
assert_eq!(-4_i32, N4::to_int()); assert_eq!(-4_i32, N4::to_int());
assert_eq!(0_i32, Z0::INT);
assert_eq!(1_i32, P1::INT);
assert_eq!(2_i32, P2::INT);
assert_eq!(3_i32, P3::INT);
assert_eq!(4_i32, P4::INT);
assert_eq!(-1_i32, N1::INT);
assert_eq!(-2_i32, N2::INT);
assert_eq!(-3_i32, N3::INT);
assert_eq!(-4_i32, N4::INT);
// i64 // i64
assert_eq!(0_i64, Z0::to_int()); assert_eq!(0_i64, Z0::to_int());
@ -1349,5 +1388,14 @@ mod tests {
assert_eq!(-2_i64, N2::to_int()); assert_eq!(-2_i64, N2::to_int());
assert_eq!(-3_i64, N3::to_int()); assert_eq!(-3_i64, N3::to_int());
assert_eq!(-4_i64, N4::to_int()); assert_eq!(-4_i64, N4::to_int());
assert_eq!(0_i64, Z0::INT);
assert_eq!(1_i64, P1::INT);
assert_eq!(2_i64, P2::INT);
assert_eq!(3_i64, P3::INT);
assert_eq!(4_i64, P4::INT);
assert_eq!(-1_i64, N1::INT);
assert_eq!(-2_i64, N2::INT);
assert_eq!(-3_i64, N3::INT);
assert_eq!(-4_i64, N4::INT);
} }
} }

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

@ -59,7 +59,7 @@
) )
)] )]
#![cfg_attr(feature = "cargo-clippy", deny(clippy::missing_inline_in_public_items))] #![cfg_attr(feature = "cargo-clippy", deny(clippy::missing_inline_in_public_items))]
#![doc(html_root_url = "https://docs.rs/typenum/1.15.0")] #![doc(html_root_url = "https://docs.rs/typenum/1.16.0")]
// For debugging macros: // For debugging macros:
// #![feature(trace_macros)] // #![feature(trace_macros)]
@ -71,12 +71,16 @@ use core::cmp::Ordering;
mod generated { mod generated {
include!(concat!(env!("OUT_DIR"), "/op.rs")); include!(concat!(env!("OUT_DIR"), "/op.rs"));
include!(concat!(env!("OUT_DIR"), "/consts.rs")); include!(concat!(env!("OUT_DIR"), "/consts.rs"));
#[cfg(feature = "const-generics")]
include!(concat!(env!("OUT_DIR"), "/generic_const_mappings.rs"));
} }
#[cfg(not(feature = "force_unix_path_separator"))] #[cfg(not(feature = "force_unix_path_separator"))]
mod generated { mod generated {
include!(env!("TYPENUM_BUILD_OP")); include!(env!("TYPENUM_BUILD_OP"));
include!(env!("TYPENUM_BUILD_CONSTS")); include!(env!("TYPENUM_BUILD_CONSTS"));
#[cfg(feature = "const-generics")]
include!(env!("TYPENUM_BUILD_GENERIC_CONSTS"));
} }
pub mod bit; pub mod bit;
@ -91,7 +95,6 @@ pub mod array;
pub use crate::{ pub use crate::{
array::{ATerm, TArr}, array::{ATerm, TArr},
consts::*,
generated::consts, generated::consts,
int::{NInt, PInt}, int::{NInt, PInt},
marker_traits::*, marker_traits::*,
@ -100,6 +103,21 @@ pub use crate::{
uint::{UInt, UTerm}, uint::{UInt, UTerm},
}; };
#[doc(no_inline)]
#[rustfmt::skip]
pub use consts::{
False, True, B0, B1,
U0, U1, U2, *,
N1, N2, Z0, P1, P2, *,
};
#[cfg(feature = "const-generics")]
pub use crate::generated::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 /// A potential output from `Cmp`, this is the type equivalent to the enum variant
/// `core::cmp::Ordering::Greater`. /// `core::cmp::Ordering::Greater`.
#[derive(Eq, PartialEq, Ord, PartialOrd, Clone, Copy, Hash, Debug, Default)] #[derive(Eq, PartialEq, Ord, PartialOrd, Clone, Copy, Hash, Debug, Default)]

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

@ -587,4 +587,6 @@ pub trait Gcd<Rhs> {
pub trait ToInt<T> { pub trait ToInt<T> {
/// Method returning the concrete value for the type. /// Method returning the concrete value for the type.
fn to_int() -> T; fn to_int() -> T;
/// The concrete value for the type. Can be used in `const` contexts.
const INT: T;
} }

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

@ -2326,6 +2326,7 @@ impl ToInt<i8> for UTerm {
fn to_int() -> i8 { fn to_int() -> i8 {
Self::I8 Self::I8
} }
const INT: i8 = Self::I8;
} }
impl ToInt<i16> for UTerm { impl ToInt<i16> for UTerm {
@ -2333,6 +2334,7 @@ impl ToInt<i16> for UTerm {
fn to_int() -> i16 { fn to_int() -> i16 {
Self::I16 Self::I16
} }
const INT: i16 = Self::I16;
} }
impl ToInt<i32> for UTerm { impl ToInt<i32> for UTerm {
@ -2340,6 +2342,7 @@ impl ToInt<i32> for UTerm {
fn to_int() -> i32 { fn to_int() -> i32 {
Self::I32 Self::I32
} }
const INT: i32 = Self::I32;
} }
impl ToInt<i64> for UTerm { impl ToInt<i64> for UTerm {
@ -2347,6 +2350,7 @@ impl ToInt<i64> for UTerm {
fn to_int() -> i64 { fn to_int() -> i64 {
Self::I64 Self::I64
} }
const INT: i64 = Self::I64;
} }
impl ToInt<u8> for UTerm { impl ToInt<u8> for UTerm {
@ -2354,6 +2358,7 @@ impl ToInt<u8> for UTerm {
fn to_int() -> u8 { fn to_int() -> u8 {
Self::U8 Self::U8
} }
const INT: u8 = Self::U8;
} }
impl ToInt<u16> for UTerm { impl ToInt<u16> for UTerm {
@ -2361,6 +2366,7 @@ impl ToInt<u16> for UTerm {
fn to_int() -> u16 { fn to_int() -> u16 {
Self::U16 Self::U16
} }
const INT: u16 = Self::U16;
} }
impl ToInt<u32> for UTerm { impl ToInt<u32> for UTerm {
@ -2368,6 +2374,7 @@ impl ToInt<u32> for UTerm {
fn to_int() -> u32 { fn to_int() -> u32 {
Self::U32 Self::U32
} }
const INT: u32 = Self::U32;
} }
impl ToInt<u64> for UTerm { impl ToInt<u64> for UTerm {
@ -2375,6 +2382,7 @@ impl ToInt<u64> for UTerm {
fn to_int() -> u64 { fn to_int() -> u64 {
Self::U64 Self::U64
} }
const INT: u64 = Self::U64;
} }
impl ToInt<usize> for UTerm { impl ToInt<usize> for UTerm {
@ -2382,6 +2390,7 @@ impl ToInt<usize> for UTerm {
fn to_int() -> usize { fn to_int() -> usize {
Self::USIZE Self::USIZE
} }
const INT: usize = Self::USIZE;
} }
impl<U, B> ToInt<i8> for UInt<U, B> impl<U, B> ToInt<i8> for UInt<U, B>
@ -2393,6 +2402,7 @@ where
fn to_int() -> i8 { fn to_int() -> i8 {
Self::I8 Self::I8
} }
const INT: i8 = Self::I8;
} }
impl<U, B> ToInt<i16> for UInt<U, B> impl<U, B> ToInt<i16> for UInt<U, B>
@ -2404,6 +2414,7 @@ where
fn to_int() -> i16 { fn to_int() -> i16 {
Self::I16 Self::I16
} }
const INT: i16 = Self::I16;
} }
impl<U, B> ToInt<i32> for UInt<U, B> impl<U, B> ToInt<i32> for UInt<U, B>
@ -2415,6 +2426,7 @@ where
fn to_int() -> i32 { fn to_int() -> i32 {
Self::I32 Self::I32
} }
const INT: i32 = Self::I32;
} }
impl<U, B> ToInt<i64> for UInt<U, B> impl<U, B> ToInt<i64> for UInt<U, B>
@ -2426,6 +2438,7 @@ where
fn to_int() -> i64 { fn to_int() -> i64 {
Self::I64 Self::I64
} }
const INT: i64 = Self::I64;
} }
impl<U, B> ToInt<u8> for UInt<U, B> impl<U, B> ToInt<u8> for UInt<U, B>
@ -2437,6 +2450,7 @@ where
fn to_int() -> u8 { fn to_int() -> u8 {
Self::U8 Self::U8
} }
const INT: u8 = Self::U8;
} }
impl<U, B> ToInt<u16> for UInt<U, B> impl<U, B> ToInt<u16> for UInt<U, B>
@ -2448,6 +2462,7 @@ where
fn to_int() -> u16 { fn to_int() -> u16 {
Self::U16 Self::U16
} }
const INT: u16 = Self::U16;
} }
impl<U, B> ToInt<u32> for UInt<U, B> impl<U, B> ToInt<u32> for UInt<U, B>
@ -2459,6 +2474,7 @@ where
fn to_int() -> u32 { fn to_int() -> u32 {
Self::U32 Self::U32
} }
const INT: u32 = Self::U32;
} }
impl<U, B> ToInt<u64> for UInt<U, B> impl<U, B> ToInt<u64> for UInt<U, B>
@ -2470,6 +2486,7 @@ where
fn to_int() -> u64 { fn to_int() -> u64 {
Self::U64 Self::U64
} }
const INT: u64 = Self::U64;
} }
impl<U, B> ToInt<usize> for UInt<U, B> impl<U, B> ToInt<usize> for UInt<U, B>
@ -2481,6 +2498,7 @@ where
fn to_int() -> usize { fn to_int() -> usize {
Self::USIZE Self::USIZE
} }
const INT: usize = Self::USIZE;
} }
#[cfg(test)] #[cfg(test)]
@ -2540,6 +2558,11 @@ mod tests {
assert_eq!(2_i8, U2::to_int()); assert_eq!(2_i8, U2::to_int());
assert_eq!(3_i8, U3::to_int()); assert_eq!(3_i8, U3::to_int());
assert_eq!(4_i8, U4::to_int()); assert_eq!(4_i8, U4::to_int());
assert_eq!(0_i8, U0::INT);
assert_eq!(1_i8, U1::INT);
assert_eq!(2_i8, U2::INT);
assert_eq!(3_i8, U3::INT);
assert_eq!(4_i8, U4::INT);
// i16 // i16
assert_eq!(0_i16, U0::to_int()); assert_eq!(0_i16, U0::to_int());
@ -2547,6 +2570,11 @@ mod tests {
assert_eq!(2_i16, U2::to_int()); assert_eq!(2_i16, U2::to_int());
assert_eq!(3_i16, U3::to_int()); assert_eq!(3_i16, U3::to_int());
assert_eq!(4_i16, U4::to_int()); assert_eq!(4_i16, U4::to_int());
assert_eq!(0_i16, U0::INT);
assert_eq!(1_i16, U1::INT);
assert_eq!(2_i16, U2::INT);
assert_eq!(3_i16, U3::INT);
assert_eq!(4_i16, U4::INT);
// i32 // i32
assert_eq!(0_i32, U0::to_int()); assert_eq!(0_i32, U0::to_int());
@ -2554,6 +2582,11 @@ mod tests {
assert_eq!(2_i32, U2::to_int()); assert_eq!(2_i32, U2::to_int());
assert_eq!(3_i32, U3::to_int()); assert_eq!(3_i32, U3::to_int());
assert_eq!(4_i32, U4::to_int()); assert_eq!(4_i32, U4::to_int());
assert_eq!(0_i32, U0::INT);
assert_eq!(1_i32, U1::INT);
assert_eq!(2_i32, U2::INT);
assert_eq!(3_i32, U3::INT);
assert_eq!(4_i32, U4::INT);
// i64 // i64
assert_eq!(0_i64, U0::to_int()); assert_eq!(0_i64, U0::to_int());
@ -2561,6 +2594,11 @@ mod tests {
assert_eq!(2_i64, U2::to_int()); assert_eq!(2_i64, U2::to_int());
assert_eq!(3_i64, U3::to_int()); assert_eq!(3_i64, U3::to_int());
assert_eq!(4_i64, U4::to_int()); assert_eq!(4_i64, U4::to_int());
assert_eq!(0_i64, U0::INT);
assert_eq!(1_i64, U1::INT);
assert_eq!(2_i64, U2::INT);
assert_eq!(3_i64, U3::INT);
assert_eq!(4_i64, U4::INT);
// u8 // u8
assert_eq!(0_u8, U0::to_int()); assert_eq!(0_u8, U0::to_int());
@ -2568,6 +2606,11 @@ mod tests {
assert_eq!(2_u8, U2::to_int()); assert_eq!(2_u8, U2::to_int());
assert_eq!(3_u8, U3::to_int()); assert_eq!(3_u8, U3::to_int());
assert_eq!(4_u8, U4::to_int()); assert_eq!(4_u8, U4::to_int());
assert_eq!(0_u8, U0::INT);
assert_eq!(1_u8, U1::INT);
assert_eq!(2_u8, U2::INT);
assert_eq!(3_u8, U3::INT);
assert_eq!(4_u8, U4::INT);
// u16 // u16
assert_eq!(0_u16, U0::to_int()); assert_eq!(0_u16, U0::to_int());
@ -2575,6 +2618,11 @@ mod tests {
assert_eq!(2_u16, U2::to_int()); assert_eq!(2_u16, U2::to_int());
assert_eq!(3_u16, U3::to_int()); assert_eq!(3_u16, U3::to_int());
assert_eq!(4_u16, U4::to_int()); assert_eq!(4_u16, U4::to_int());
assert_eq!(0_u16, U0::INT);
assert_eq!(1_u16, U1::INT);
assert_eq!(2_u16, U2::INT);
assert_eq!(3_u16, U3::INT);
assert_eq!(4_u16, U4::INT);
// u32 // u32
assert_eq!(0_u32, U0::to_int()); assert_eq!(0_u32, U0::to_int());
@ -2582,6 +2630,11 @@ mod tests {
assert_eq!(2_u32, U2::to_int()); assert_eq!(2_u32, U2::to_int());
assert_eq!(3_u32, U3::to_int()); assert_eq!(3_u32, U3::to_int());
assert_eq!(4_u32, U4::to_int()); assert_eq!(4_u32, U4::to_int());
assert_eq!(0_u32, U0::INT);
assert_eq!(1_u32, U1::INT);
assert_eq!(2_u32, U2::INT);
assert_eq!(3_u32, U3::INT);
assert_eq!(4_u32, U4::INT);
// u64 // u64
assert_eq!(0_u64, U0::to_int()); assert_eq!(0_u64, U0::to_int());
@ -2589,6 +2642,11 @@ mod tests {
assert_eq!(2_u64, U2::to_int()); assert_eq!(2_u64, U2::to_int());
assert_eq!(3_u64, U3::to_int()); assert_eq!(3_u64, U3::to_int());
assert_eq!(4_u64, U4::to_int()); assert_eq!(4_u64, U4::to_int());
assert_eq!(0_u64, U0::INT);
assert_eq!(1_u64, U1::INT);
assert_eq!(2_u64, U2::INT);
assert_eq!(3_u64, U3::INT);
assert_eq!(4_u64, U4::INT);
// usize // usize
assert_eq!(0_usize, U0::to_int()); assert_eq!(0_usize, U0::to_int());
@ -2596,5 +2654,10 @@ mod tests {
assert_eq!(2_usize, U2::to_int()); assert_eq!(2_usize, U2::to_int());
assert_eq!(3_usize, U3::to_int()); assert_eq!(3_usize, U3::to_int());
assert_eq!(4_usize, U4::to_int()); assert_eq!(4_usize, U4::to_int());
assert_eq!(0_usize, U0::INT);
assert_eq!(1_usize, U1::INT);
assert_eq!(2_usize, U2::INT);
assert_eq!(3_usize, U3::INT);
assert_eq!(4_usize, U4::INT);
} }
} }