Skip to content

Commit f65ecc5

Browse files
committed
own ConstZero/One
1 parent 3a26769 commit f65ecc5

File tree

4 files changed

+18
-8
lines changed

4 files changed

+18
-8
lines changed

ci/script.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ main() {
4343
echo 'cortex-m = "0.7.7"' >> $td/Cargo.toml
4444
echo 'cortex-m-rt = "0.7.3"' >> $td/Cargo.toml
4545
echo 'vcell = "0.1.3"' >> $td/Cargo.toml
46-
echo 'num-traits = { version = "0.2.19", default-features = false }' >> $td/Cargo.toml
4746
if [[ "$options" == *"--atomics"* ]]; then
4847
echo 'portable-atomic = { version = "1.4", default-features = false }' >> $td/Cargo.toml
4948
fi

ci/svd2rust-regress/src/svd_test.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use std::{
1313

1414
const CRATES_ALL: &[&str] = &[
1515
"critical-section = {version = \"1.0\", optional = true}",
16-
"num-traits = { version = \"0.2.19\", default-features = false }",
1716
"vcell = \"0.1.2\"",
1817
];
1918
const CRATES_MSP430: &[&str] = &["msp430 = \"0.4.0\"", "msp430-rt = \"0.4.0\""];

src/generate/generic.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
use core::marker;
2-
use num_traits::{ConstOne, ConstZero};
2+
3+
/// Defines an associated constant representing the additive identity element
4+
/// for `Self`.
5+
pub trait ConstZero {
6+
/// The additive identity element of `Self`, `0`.
7+
const ZERO: Self;
8+
}
9+
10+
pub trait ConstOne: One {
11+
/// The multiplicative identity element of `Self`, `1`.
12+
const ONE: Self;
13+
}
314

415
/// Raw register type (`u8`, `u16`, `u32`, ...)
516
pub trait RawReg:
@@ -26,6 +37,12 @@ macro_rules! raw_reg {
2637
$mask::<WI>()
2738
}
2839
}
40+
impl ConstZero for $U {
41+
const ZERO: Self = 0;
42+
}
43+
impl ConstOne for $U {
44+
const ONE: Self = 1;
45+
}
2946
const fn $mask<const WI: u8>() -> $U {
3047
<$U>::MAX >> ($size - WI)
3148
}

src/lib.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@
6262
//! - [`cortex-m`](https://crates.io/crates/cortex-m) >=v0.7.6
6363
//! - [`cortex-m-rt`](https://crates.io/crates/cortex-m-rt) >=v0.6.13
6464
//! - [`vcell`](https://crates.io/crates/vcell) >=v0.1.2
65-
//! - [`num-traits`](https://crates.io/crates/const-default) >=v0.2.18
6665
//!
6766
//! Furthermore, the "device" feature of `cortex-m-rt` must be enabled when the `rt` feature
6867
//! is enabled. The `Cargo.toml` of the device crate will look like this:
@@ -127,7 +126,6 @@
127126
//! - [`msp430`](https://crates.io/crates/msp430) v0.4.x
128127
//! - [`msp430-rt`](https://crates.io/crates/msp430-rt) v0.4.x
129128
//! - [`vcell`](https://crates.io/crates/vcell) v0.1.x
130-
//! - [`num-traits`](https://crates.io/crates/const-default) v0.2.x
131129
//!
132130
//! The "device" feature of `msp430-rt` must be enabled when the `rt` feature is
133131
//! enabled. The `Cargo.toml` of the device crate will look like this:
@@ -138,7 +136,6 @@
138136
//! msp430 = "0.4.0"
139137
//! msp430-rt = { version = "0.4.0", optional = true }
140138
//! vcell = "0.1.0"
141-
//! num-traits = { version = "0.2.19", default-features = false }
142139
//!
143140
//! [features]
144141
//! rt = ["msp430-rt/device"]
@@ -156,7 +153,6 @@
156153
//! - [`riscv-peripheral`](https://crates.io/crates/riscv-peripheral) v0.2.x (if target is RISC-V and has standard peripherals)
157154
//! - [`riscv-rt`](https://crates.io/crates/riscv-rt) v0.13.x (if target is RISC-V)
158155
//! - [`vcell`](https://crates.io/crates/vcell) v0.1.x
159-
//! - [`num-traits`](https://crates.io/crates/const-default) v0.2.x
160156
//!
161157
//! The `*-rt` dependencies must be optional only enabled when the `rt` feature is enabled.
162158
//! If target is RISC-V and supports vectored mode, you must include a feature `v-trap` to activate `riscv-rt/v-trap`.
@@ -169,7 +165,6 @@
169165
//! riscv-peripheral = "0.2.0"
170166
//! riscv-rt = { version = "0.13.0", optional = true }
171167
//! vcell = "0.1.0"
172-
//! num-traits = { version = "0.2.19", default-features = false }
173168
//!
174169
//! [features]
175170
//! rt = ["riscv-rt"]

0 commit comments

Comments
 (0)