Skip to content

Commit 4ca742a

Browse files
authored
Merge branch 'master' into reverse-bits
2 parents 94761f7 + ee28ebb commit 4ca742a

File tree

7 files changed

+235
-263
lines changed

7 files changed

+235
-263
lines changed

README.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,6 @@ Add this to your `Cargo.toml`:
1616
num-traits = "0.2"
1717
```
1818

19-
and this to your crate root:
20-
21-
```rust
22-
extern crate num_traits;
23-
```
24-
2519
## Features
2620

2721
This crate can be used without the standard library (`#![no_std]`) by disabling

build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ fn main() {
1717
);
1818

1919
ac.emit_expression_cfg("1u32.reverse_bits()", "has_reverse_bits");
20+
ac.emit_expression_cfg("1u32.trailing_ones()", "has_leading_trailing_ones");
2021

2122
autocfg::rerun_path("build.rs");
2223
}

src/bounds.rs

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,38 @@ use core::{u16, u32, u64, u8, usize};
88
/// Numbers which have upper and lower bounds
99
pub trait Bounded {
1010
// FIXME (#5527): These should be associated constants
11-
/// returns the smallest finite number this type can represent
11+
/// Returns the smallest finite number this type can represent
1212
fn min_value() -> Self;
13-
/// returns the largest finite number this type can represent
13+
/// Returns the largest finite number this type can represent
1414
fn max_value() -> Self;
1515
}
1616

17+
/// Numbers which have lower bounds
18+
pub trait LowerBounded {
19+
/// Returns the smallest finite number this type can represent
20+
fn min_value() -> Self;
21+
}
22+
23+
// FIXME: With a major version bump, this should be a supertrait instead
24+
impl<T: Bounded> LowerBounded for T {
25+
fn min_value() -> T {
26+
Bounded::min_value()
27+
}
28+
}
29+
30+
/// Numbers which have upper bounds
31+
pub trait UpperBounded {
32+
/// Returns the largest finite number this type can represent
33+
fn max_value() -> Self;
34+
}
35+
36+
// FIXME: With a major version bump, this should be a supertrait instead
37+
impl<T: Bounded> UpperBounded for T {
38+
fn max_value() -> T {
39+
Bounded::max_value()
40+
}
41+
}
42+
1743
macro_rules! bounded_impl {
1844
($t:ty, $min:expr, $max:expr) => {
1945
impl Bounded for $t {

0 commit comments

Comments
 (0)