Skip to content

Commit cec1cef

Browse files
authored
Merge pull request #12 from cuviper/msrv-1.90
Add new methods for MSRV 1.90
2 parents 8b45612 + d01c463 commit cec1cef

5 files changed

Lines changed: 31 additions & 6 deletions

File tree

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
strategy:
1313
matrix:
1414
rust: [
15-
1.87.0, # MSRV
15+
1.90.0, # MSRV
1616
stable,
1717
beta,
1818
nightly,
@@ -52,7 +52,7 @@ jobs:
5252
runs-on: ubuntu-latest
5353
steps:
5454
- uses: actions/checkout@v4
55-
- uses: dtolnay/rust-toolchain@1.87.0
55+
- uses: dtolnay/rust-toolchain@1.90.0
5656
with:
5757
components: rustfmt
5858
- run: cargo fmt --all --check

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
[package]
22
name = "num-primitive"
3-
version = "0.3.0"
3+
version = "0.3.1"
44
description = "Traits for primitive numeric types"
55
repository = "https://github.com/rust-num/num-primitive"
66
license = "MIT OR Apache-2.0"
77
keywords = ["generic", "mathematics", "numerics", "primitive"]
88
categories = ["algorithms", "science", "no-std"]
99
edition = "2024"
10-
rust-version = "1.87"
10+
rust-version = "1.90"
1111

1212
[features]
1313
default = ["std"]

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[![crate](https://img.shields.io/crates/v/num-primitive.svg)](https://crates.io/crates/num-primitive)
44
[![documentation](https://docs.rs/num-primitive/badge.svg)](https://docs.rs/num-primitive)
5-
[![minimum rustc 1.87](https://img.shields.io/badge/rustc-1.87+-red.svg)](https://rust-lang.github.io/rfcs/2495-min-rust-version.html)
5+
[![minimum rustc 1.90](https://img.shields.io/badge/rustc-1.90+-red.svg)](https://rust-lang.github.io/rfcs/2495-min-rust-version.html)
66
[![build status](https://github.com/rust-num/num-primitive/workflows/CI/badge.svg)](https://github.com/rust-num/num-primitive/actions)
77

88
Traits for primitive numeric types in Rust.
@@ -61,7 +61,7 @@ Release notes are available in [RELEASES.md](RELEASES.md).
6161

6262
## Compatibility
6363

64-
The `num-primitive` crate is currently tested for Rust 1.87 and greater. This
64+
The `num-primitive` crate is currently tested for Rust 1.90 and greater. This
6565
minimum-supported Rust version (MSRV) may be increased at any time to add
6666
support for newly-stabilized functionality from the standard library. Changes
6767
will be documented prominently in the release notes.

RELEASES.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# Release 0.3.1 (2025-12-16)
2+
3+
- Updated to MSRV 1.90.
4+
- Added `PrimitiveUnsigned::{checked,overflowing,saturating,wrapping}_sub_signed`
5+
16
# Release 0.3.0 (2025-12-16)
27

38
- Added `PrimitiveNumber::midpoint`

src/unsigned.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ pub trait PrimitiveUnsigned: PrimitiveInteger + From<u8> {
5656
/// wrapped in Some.
5757
fn checked_next_power_of_two(self) -> Option<Self>;
5858

59+
/// Checked subtraction with a signed integer. Computes `self - rhs`,
60+
/// returning `None` if overflow occurred.
61+
fn checked_sub_signed(self, rhs: Self::Signed) -> Option<Self>;
62+
5963
/// Calculates the quotient of `self` and rhs, rounding the result towards positive infinity.
6064
fn div_ceil(self, rhs: Self) -> Self;
6165

@@ -75,13 +79,25 @@ pub trait PrimitiveUnsigned: PrimitiveInteger + From<u8> {
7579
/// boolean indicating whether an arithmetic overflow would occur.
7680
fn overflowing_add_signed(self, rhs: Self::Signed) -> (Self, bool);
7781

82+
/// Calculates `self` - `rhs` with a signed `rhs`. Returns a tuple of the subtraction along
83+
/// with a boolean indicating whether an arithmetic overflow would occur.
84+
fn overflowing_sub_signed(self, rhs: Self::Signed) -> (Self, bool);
85+
7886
/// Saturating addition with a signed integer. Computes `self + rhs`, saturating at the numeric
7987
/// bounds instead of overflowing.
8088
fn saturating_add_signed(self, rhs: Self::Signed) -> Self;
8189

90+
/// Saturating integer subtraction. Computes `self` - `rhs`, saturating at
91+
/// the numeric bounds instead of overflowing.
92+
fn saturating_sub_signed(self, rhs: Self::Signed) -> Self;
93+
8294
/// Wrapping (modular) addition with a signed integer. Computes `self + rhs`, wrapping around
8395
/// at the boundary of the type.
8496
fn wrapping_add_signed(self, rhs: Self::Signed) -> Self;
97+
98+
/// Wrapping (modular) subtraction with a signed integer. Computes
99+
/// `self - rhs`, wrapping around at the boundary of the type.
100+
fn wrapping_sub_signed(self, rhs: Self::Signed) -> Self;
85101
}
86102

87103
/// Trait for references to primitive unsigned integer types ([`PrimitiveUnsigned`]).
@@ -101,14 +117,18 @@ macro_rules! impl_unsigned {
101117
fn checked_add_signed(self, rhs: Self::Signed) -> Option<Self>;
102118
fn checked_next_multiple_of(self, rhs: Self) -> Option<Self>;
103119
fn checked_next_power_of_two(self) -> Option<Self>;
120+
fn checked_sub_signed(self, rhs: Self::Signed) -> Option<Self>;
104121
fn div_ceil(self, rhs: Self) -> Self;
105122
fn is_multiple_of(self, rhs: Self) -> bool;
106123
fn is_power_of_two(self) -> bool;
107124
fn next_multiple_of(self, rhs: Self) -> Self;
108125
fn next_power_of_two(self) -> Self;
109126
fn overflowing_add_signed(self, rhs: Self::Signed) -> (Self, bool);
127+
fn overflowing_sub_signed(self, rhs: Self::Signed) -> (Self, bool);
110128
fn saturating_add_signed(self, rhs: Self::Signed) -> Self;
129+
fn saturating_sub_signed(self, rhs: Self::Signed) -> Self;
111130
fn wrapping_add_signed(self, rhs: Self::Signed) -> Self;
131+
fn wrapping_sub_signed(self, rhs: Self::Signed) -> Self;
112132
}
113133
}
114134

0 commit comments

Comments
 (0)