From 1ff35d407dd942afcf1d5f0933e6ac6e938fcb7e Mon Sep 17 00:00:00 2001 From: mn13 Date: Sun, 26 Dec 2021 09:38:54 +0300 Subject: [PATCH] add scale_info feauture (#175) add optional scale_info feature * add scale_info for - UInt - B0 - B1 - UTerm * scale_info derive for - Greater - Less - Equal - PInt - NInt - ATerm - TArr Co-authored-by: Maks Nabokov --- CHANGELOG.md | 4 ++++ Cargo.toml | 6 +++++- src/array.rs | 2 ++ src/bit.rs | 2 ++ src/int.rs | 3 +++ src/lib.rs | 5 ++++- src/uint.rs | 2 ++ 7 files changed, 22 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 924dc4b1b..7a0bc5ab5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ against this Rust version. ### Unreleased - [fixed] Cross-compilation issue due to doing math in build script. +### 1.15.0 (2021-12-06) +- [added] New feauture `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 diff --git a/Cargo.toml b/Cargo.toml index a7b1175c6..3aab04458 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "typenum" build = "build/main.rs" - version = "1.14.0" # remember to update html_root_url + version = "1.15.0" # remember to update html_root_url authors = [ "Paho Lurie-Gregg ", "Andre Bogus " @@ -17,6 +17,9 @@ categories = ["no-std"] edition = "2018" +[dependencies] +scale-info = { version = "1.0", default-features = false, optional=true } + [lib] name = "typenum" @@ -25,3 +28,4 @@ i128 = [] strict = [] force_unix_path_separator = [] + scale_info = ["scale-info/derive"] diff --git a/src/array.rs b/src/array.rs index d70bf3924..08eedbe6d 100644 --- a/src/array.rs +++ b/src/array.rs @@ -8,6 +8,7 @@ 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 {} @@ -19,6 +20,7 @@ impl TypeArray for ATerm {} /// 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 { first: V, rest: A, diff --git a/src/bit.rs b/src/bit.rs index 4ed072dc6..4a098fe84 100644 --- a/src/bit.rs +++ b/src/bit.rs @@ -16,6 +16,7 @@ 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 { @@ -28,6 +29,7 @@ impl 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 { diff --git a/src/int.rs b/src/int.rs index fd5ee967a..0140858a4 100644 --- a/src/int.rs +++ b/src/int.rs @@ -38,12 +38,14 @@ use core::ops::{Add, Div, Mul, Neg, Rem, Sub}; /// Type-level signed integers with positive sign. #[derive(Eq, PartialEq, Ord, PartialOrd, Clone, Copy, Hash, Debug, Default)] +#[cfg_attr(feature = "scale_info", derive(scale_info::TypeInfo))] pub struct PInt { pub(crate) n: U, } /// Type-level signed integers with negative sign. #[derive(Eq, PartialEq, Ord, PartialOrd, Clone, Copy, Hash, Debug, Default)] +#[cfg_attr(feature = "scale_info", derive(scale_info::TypeInfo))] pub struct NInt { pub(crate) n: U, } @@ -66,6 +68,7 @@ impl NInt { /// The type-level signed integer 0. #[derive(Eq, PartialEq, Ord, PartialOrd, Clone, Copy, Hash, Debug, Default)] +#[cfg_attr(feature = "scale_info", derive(scale_info::TypeInfo))] pub struct Z0; impl Z0 { diff --git a/src/lib.rs b/src/lib.rs index 409af76f4..98367c802 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -59,7 +59,7 @@ ) )] #![cfg_attr(feature = "cargo-clippy", deny(clippy::missing_inline_in_public_items))] -#![doc(html_root_url = "https://docs.rs/typenum/1.14.0")] +#![doc(html_root_url = "https://docs.rs/typenum/1.15.0")] // For debugging macros: // #![feature(trace_macros)] @@ -103,16 +103,19 @@ pub use crate::{ /// 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` diff --git a/src/uint.rs b/src/uint.rs index aed884fe8..8fc3d6182 100644 --- a/src/uint.rs +++ b/src/uint.rs @@ -46,6 +46,7 @@ pub use crate::marker_traits::{PowerOfTwo, Unsigned}; /// The terminating type for `UInt`; it always comes after the most significant /// bit. `UTerm` by itself represents zero, which is aliased to `U0`. #[derive(Eq, PartialEq, Ord, PartialOrd, Clone, Copy, Hash, Debug, Default)] +#[cfg_attr(feature = "scale_info", derive(scale_info::TypeInfo))] pub struct UTerm; impl UTerm { @@ -143,6 +144,7 @@ impl Unsigned for UTerm { /// type U6 = UInt, B1>, B0>; /// ``` #[derive(Eq, PartialEq, Ord, PartialOrd, Clone, Copy, Hash, Debug, Default)] +#[cfg_attr(feature = "scale_info", derive(scale_info::TypeInfo))] pub struct UInt { /// The more significant bits of `Self`. pub(crate) msb: U,