Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions library/core/src/num/saturating.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::ops::{
Add, AddAssign, BitAnd, BitAndAssign, BitOr, BitOrAssign, BitXor, BitXorAssign, Div, DivAssign,
Mul, MulAssign, Neg, Not, Rem, RemAssign, Sub, SubAssign,
};
use crate::random::{Random, RandomSource};

/// Provides intentionally-saturating arithmetic on `T`.
///
Expand Down Expand Up @@ -79,6 +80,13 @@ impl<T: fmt::UpperHex> fmt::UpperHex for Saturating<T> {
}
}

#[unstable(feature = "random", issue = "130703")]
impl<T: Random> Random for Saturating<T> {
fn random(source: &mut (impl RandomSource + ?Sized)) -> Self {
Self(T::random(source))
}
}

// FIXME the correct implementation is not clear. Waiting for a real world use case at https://github.com/rust-lang/libs-team/issues/230
//
// #[allow(unused_macros)]
Expand Down
8 changes: 8 additions & 0 deletions library/core/src/num/wrapping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::ops::{
Add, AddAssign, BitAnd, BitAndAssign, BitOr, BitOrAssign, BitXor, BitXorAssign, Div, DivAssign,
Mul, MulAssign, Neg, Not, Rem, RemAssign, Shl, ShlAssign, Shr, ShrAssign, Sub, SubAssign,
};
use crate::random::{Random, RandomSource};

/// Provides intentionally-wrapped arithmetic on `T`.
///
Expand Down Expand Up @@ -84,6 +85,13 @@ impl<T: fmt::UpperHex> fmt::UpperHex for Wrapping<T> {
}
}

#[unstable(feature = "random", issue = "130703")]
impl<T: Random> Random for Wrapping<T> {
fn random(source: &mut (impl RandomSource + ?Sized)) -> Self {
Self(T::random(source))
}
}

#[allow(unused_macros)]
macro_rules! sh_impl_signed {
($t:ident, $f:ident) => {
Expand Down
Loading