Skip to content

Commit 305532d

Browse files
Merge #210
210: Add LowerBounded/UpperBounded traits r=cuviper a=clarfonthey Potential solution for #208. With a breaking change, these could simply become supertraits of `Bounded`, but until then, we have to deal with blanket implementations. I added both simply because it was easy to do so, although we could opt to not require both. I don't see it being that negative to include both, however. Co-authored-by: ltdk <[email protected]>
2 parents d134b8c + f9422e7 commit 305532d

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

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)