Skip to content

Commit 5a5cd83

Browse files
authored
Merge pull request #13 from popzxc/prepare-release
Prepare release 0.3
2 parents 2c3739d + 2179f94 commit 5a5cd83

File tree

6 files changed

+78
-16
lines changed

6 files changed

+78
-16
lines changed

CHANGELOG.md

+15-6
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,24 @@
22

33
## [[Unreleased]]
44

5-
- `try_match` and `unwrap_match` macros to get a certain variant from an enum.
6-
- `return_ok` and `return_some` macros for early return of successful calculation.
7-
- `Integer` trait that unifies all the built-in integer types under a single interface.
8-
- `FloatConvert` trait that adds an interface for converting floating point numbers into integers.
5+
## 0.3.0 (18.06.2021)
6+
7+
- `try_match` and `unwrap_match` macros to get a certain variant from an enum [#11].
8+
- `return_ok` and `return_some` macros for early return of successful calculation [#11].
9+
- `Integer` trait that unifies all the built-in integer types under a single interface [#12].
10+
- `FloatConvert` trait that adds an interface for converting floating point numbers into integers [#12].
11+
12+
[#11]: https://github.com/popzxc/stdext-rs/pull/11
13+
[#12]: https://github.com/popzxc/stdext-rs/pull/12
914

1015
## 0.2.1 (09.07.2020)
1116

12-
- `VecExt::remove_item` method was added (#9).
17+
- `VecExt::remove_item` method was added [#9].
18+
19+
[#9]: https://github.com/popzxc/stdext-rs/pull/9
1320

1421
## 0.2.0 (02.07.2020)
1522

16-
- `compile_warning` and `function_name` macros were added (#4).
23+
- `compile_warning` and `function_name` macros were added [#4].
24+
25+
[#4]: https://github.com/popzxc/stdext-rs/pull/4

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "stdext"
3-
version = "0.2.1"
3+
version = "0.3.0"
44
authors = ["Igor Aleksanov <[email protected]>"]
55
edition = "2018"
66
repository = "https://github.com/popzxc/stdext-rs"

README.md

+25
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,31 @@ functionality which possible can get to the `std` some day.
2121

2222
## Highlights
2323

24+
- `Integer` super-trait that is implemented for all the built-in integers
25+
and reflects the common part of their interfaces.
26+
27+
```rust
28+
use stdext::prelude::*;
29+
30+
fn accepts_any_integer<I: Integer>(a: I, b: I) {
31+
println!("{}", (a + b).count_ones());
32+
}
33+
```
34+
35+
- Safe conversions from floating numbers to integers.
36+
37+
```rust
38+
use stdext::prelude::FloatConvert;
39+
40+
let valid: Option<u8> = 10.5f32.checked_floor();
41+
let too_big: Option<u8> = 256f32.checked_floor();
42+
let nan: Option<u8> = f32::NAN.checked_floor();
43+
44+
assert_eq!(valid, Some(10u8));
45+
assert_eq!(too_big, None);
46+
assert_eq!(nan, None);
47+
```
48+
2449
- Convenient builder methods for **`Duration`**:
2550

2651
```rust

src/lib.rs

+13
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
//! | [`Duration`] | [`DurationExt`]
2424
//! | [`RwLock`] | [`RwLockExt`]
2525
//! | [`Mutex`] | [`MutexExt`]
26+
//! | [`f32`] and [`f64`] | [`FloatConvert`]
2627
//!
2728
//! [`Vec`]: https://doc.rust-lang.org/std/vec/struct.Vec.html
2829
//! [`&str`]: https://doc.rust-lang.org/std/primitive.str.html
@@ -40,6 +41,16 @@
4041
//! [`DurationExt`]: duration/trait.DurationExt.html
4142
//! [`RwLockExt`]: sync/rw_lock/trait.RwLockExt.html
4243
//! [`MutexExt`]: sync/mutex/trait.MutexExt.html
44+
//! [`FloatConvert`]: num/float_convert/trait.FloatConvert.html
45+
//!
46+
//! ## Integer super-trait
47+
//!
48+
//! While all built-in integer types have mostly the same interface, it's not backed by any trait,
49+
//! which makes it impossible to write a function that will accept any built-in integer.
50+
//!
51+
//! [`Integer`] trait solves that problem by reflecting the common interface of all the built-in integers.
52+
//!
53+
//! [`Integer`]: num/integer/trait.Integer.html
4354
//!
4455
//! ## Macros
4556
//!
@@ -113,6 +124,8 @@
113124
//! }
114125
//! ```
115126
127+
#![warn(missing_docs, unreachable_pub)]
128+
116129
pub mod duration;
117130
#[macro_use]
118131
pub mod macros;

src/macros.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Various helper macros.
2+
13
/// `compile_warning` macro is a brother of [`std::compile_error`],
24
/// which emits a compile-time warning with a provided message.
35
///

src/num/integer.rs

+22-9
Original file line numberDiff line numberDiff line change
@@ -25,28 +25,31 @@ use std::ops::{
2525
/// as they exist for the unsigned numbers only.
2626
pub trait Integer:
2727
Sized
28-
+ Add
28+
+ Add<Self, Output = Self>
2929
+ AddAssign
30-
+ Sub
30+
+ Sub<Self, Output = Self>
3131
+ SubAssign
32-
+ Shr
32+
+ Shr<Self, Output = Self>
3333
+ ShrAssign
34-
+ Shl
34+
+ Shl<Self, Output = Self>
3535
+ ShlAssign
36-
+ BitAnd
36+
+ BitAnd<Self, Output = Self>
3737
+ BitAndAssign
38-
+ BitOr
38+
+ BitOr<Self, Output = Self>
3939
+ BitOrAssign
40-
+ BitXor
40+
+ BitXor<Self, Output = Self>
4141
+ BitXorAssign
42-
+ Div
42+
+ Div<Self, Output = Self>
4343
+ DivAssign
44-
+ Mul
44+
+ Mul<Self, Output = Self>
4545
+ MulAssign
4646
+ Copy
4747
{
48+
/// The smallest value that can be represented by this integer type.
4849
const MIN: Self;
50+
/// The largest value that can be represented by this integer type.
4951
const MAX: Self;
52+
/// The size of this integer type in bits.
5053
const BITS: u32;
5154

5255
/// See [`u128::from_str_radix`].
@@ -453,4 +456,14 @@ mod tests {
453456
10u32.trailing_ones()
454457
);
455458
}
459+
460+
fn accepts_any_integer<I: super::Integer>(a: I, b: I) -> u32 {
461+
(a + b).count_ones()
462+
}
463+
464+
#[test]
465+
fn composite() {
466+
assert_eq!(accepts_any_integer(0u8, 0u8), 0);
467+
assert_eq!(accepts_any_integer(1i128, 0i128), 1);
468+
}
456469
}

0 commit comments

Comments
 (0)