Skip to content

Commit 1ff35d4

Browse files
mn13Maks Nabokov
andauthored
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 <[email protected]>
1 parent 273bc6b commit 1ff35d4

File tree

7 files changed

+22
-2
lines changed

7 files changed

+22
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ against this Rust version.
88
### Unreleased
99
- [fixed] Cross-compilation issue due to doing math in build script.
1010

11+
### 1.15.0 (2021-12-06)
12+
- [added] New feauture `scale_info` for using inside [Substrate](https://github.com/paritytech/substrate.git)-based runtimes
13+
(PR #175)
14+
1115
### 1.14.0 (2021-09-01)
1216
- [changed] Sealed all marker traits. Documentation already stated that these
1317
should not be implemented outside the crate, so this is not considered a

Cargo.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "typenum"
33
build = "build/main.rs"
4-
version = "1.14.0" # remember to update html_root_url
4+
version = "1.15.0" # remember to update html_root_url
55
authors = [
66
"Paho Lurie-Gregg <[email protected]>",
77
"Andre Bogus <[email protected]>"
@@ -17,6 +17,9 @@
1717
categories = ["no-std"]
1818
edition = "2018"
1919

20+
[dependencies]
21+
scale-info = { version = "1.0", default-features = false, optional=true }
22+
2023
[lib]
2124
name = "typenum"
2225

@@ -25,3 +28,4 @@
2528
i128 = []
2629
strict = []
2730
force_unix_path_separator = []
31+
scale_info = ["scale-info/derive"]

src/array.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use super::*;
88

99
/// The terminating type for type arrays.
1010
#[derive(Eq, PartialEq, Ord, PartialOrd, Clone, Copy, Hash, Debug)]
11+
#[cfg_attr(feature = "scale_info", derive(scale_info::TypeInfo))]
1112
pub struct ATerm;
1213

1314
impl TypeArray for ATerm {}
@@ -19,6 +20,7 @@ impl TypeArray for ATerm {}
1920
/// This array is only really designed to contain `Integer` types. If you use it with others, you
2021
/// may find it lacking functionality.
2122
#[derive(Eq, PartialEq, Ord, PartialOrd, Clone, Copy, Hash, Debug)]
23+
#[cfg_attr(feature = "scale_info", derive(scale_info::TypeInfo))]
2224
pub struct TArr<V, A> {
2325
first: V,
2426
rest: A,

src/bit.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ pub use crate::marker_traits::Bit;
1616

1717
/// The type-level bit 0.
1818
#[derive(Eq, PartialEq, Ord, PartialOrd, Clone, Copy, Hash, Debug, Default)]
19+
#[cfg_attr(feature = "scale_info", derive(scale_info::TypeInfo))]
1920
pub struct B0;
2021

2122
impl B0 {
@@ -28,6 +29,7 @@ impl B0 {
2829

2930
/// The type-level bit 1.
3031
#[derive(Eq, PartialEq, Ord, PartialOrd, Clone, Copy, Hash, Debug, Default)]
32+
#[cfg_attr(feature = "scale_info", derive(scale_info::TypeInfo))]
3133
pub struct B1;
3234

3335
impl B1 {

src/int.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,14 @@ use core::ops::{Add, Div, Mul, Neg, Rem, Sub};
3838

3939
/// Type-level signed integers with positive sign.
4040
#[derive(Eq, PartialEq, Ord, PartialOrd, Clone, Copy, Hash, Debug, Default)]
41+
#[cfg_attr(feature = "scale_info", derive(scale_info::TypeInfo))]
4142
pub struct PInt<U: Unsigned + NonZero> {
4243
pub(crate) n: U,
4344
}
4445

4546
/// Type-level signed integers with negative sign.
4647
#[derive(Eq, PartialEq, Ord, PartialOrd, Clone, Copy, Hash, Debug, Default)]
48+
#[cfg_attr(feature = "scale_info", derive(scale_info::TypeInfo))]
4749
pub struct NInt<U: Unsigned + NonZero> {
4850
pub(crate) n: U,
4951
}
@@ -66,6 +68,7 @@ impl<U: Unsigned + NonZero> NInt<U> {
6668

6769
/// The type-level signed integer 0.
6870
#[derive(Eq, PartialEq, Ord, PartialOrd, Clone, Copy, Hash, Debug, Default)]
71+
#[cfg_attr(feature = "scale_info", derive(scale_info::TypeInfo))]
6972
pub struct Z0;
7073

7174
impl Z0 {

src/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
)
6060
)]
6161
#![cfg_attr(feature = "cargo-clippy", deny(clippy::missing_inline_in_public_items))]
62-
#![doc(html_root_url = "https://docs.rs/typenum/1.14.0")]
62+
#![doc(html_root_url = "https://docs.rs/typenum/1.15.0")]
6363

6464
// For debugging macros:
6565
// #![feature(trace_macros)]
@@ -103,16 +103,19 @@ pub use crate::{
103103
/// A potential output from `Cmp`, this is the type equivalent to the enum variant
104104
/// `core::cmp::Ordering::Greater`.
105105
#[derive(Eq, PartialEq, Ord, PartialOrd, Clone, Copy, Hash, Debug, Default)]
106+
#[cfg_attr(feature = "scale_info", derive(scale_info::TypeInfo))]
106107
pub struct Greater;
107108

108109
/// A potential output from `Cmp`, this is the type equivalent to the enum variant
109110
/// `core::cmp::Ordering::Less`.
110111
#[derive(Eq, PartialEq, Ord, PartialOrd, Clone, Copy, Hash, Debug, Default)]
112+
#[cfg_attr(feature = "scale_info", derive(scale_info::TypeInfo))]
111113
pub struct Less;
112114

113115
/// A potential output from `Cmp`, this is the type equivalent to the enum variant
114116
/// `core::cmp::Ordering::Equal`.
115117
#[derive(Eq, PartialEq, Ord, PartialOrd, Clone, Copy, Hash, Debug, Default)]
118+
#[cfg_attr(feature = "scale_info", derive(scale_info::TypeInfo))]
116119
pub struct Equal;
117120

118121
/// Returns `core::cmp::Ordering::Greater`

src/uint.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ pub use crate::marker_traits::{PowerOfTwo, Unsigned};
4646
/// The terminating type for `UInt`; it always comes after the most significant
4747
/// bit. `UTerm` by itself represents zero, which is aliased to `U0`.
4848
#[derive(Eq, PartialEq, Ord, PartialOrd, Clone, Copy, Hash, Debug, Default)]
49+
#[cfg_attr(feature = "scale_info", derive(scale_info::TypeInfo))]
4950
pub struct UTerm;
5051

5152
impl UTerm {
@@ -143,6 +144,7 @@ impl Unsigned for UTerm {
143144
/// type U6 = UInt<UInt<UInt<UTerm, B1>, B1>, B0>;
144145
/// ```
145146
#[derive(Eq, PartialEq, Ord, PartialOrd, Clone, Copy, Hash, Debug, Default)]
147+
#[cfg_attr(feature = "scale_info", derive(scale_info::TypeInfo))]
146148
pub struct UInt<U, B> {
147149
/// The more significant bits of `Self`.
148150
pub(crate) msb: U,

0 commit comments

Comments
 (0)