about summary refs log tree commit diff
path: root/library/std
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2021-08-28 23:39:02 +0000
committerbors <bors@rust-lang.org>2021-08-28 23:39:02 +0000
commit677b517e66fe9df0b2ce72f5ec57d52cc0da506e (patch)
tree5ab3b7e2602c4b47de3587d95405807b9eb8ba1e /library/std
parent5eacec9ec7e112a0de1011519a57c45586d58414 (diff)
parentce636f25e55493f42e7339cb533cb523879b62a5 (diff)
downloadrust-677b517e66fe9df0b2ce72f5ec57d52cc0da506e.tar.gz
rust-677b517e66fe9df0b2ce72f5ec57d52cc0da506e.zip
Auto merge of #87921 - kellerkindt:master, r=kennytm
Add Saturating type (based on Wrapping type)

Tracking #87920

### Unresolved Questions
<!--
Include any open questions that need to be answered before the feature can be
stabilised.
-->

 - [x] ~`impl Div for Saturating<T>` falls back on inner integer division - which seems alright?~
    - [x] add `saturating_div`? (to respect division by `-1`)
 - [x] There is no `::saturating_shl` and `::saturating_shr`. (How to) implement `Shl`, `ShlAssign`, `Shr` and `ShrAssign`?
   - [naively](3f7d2ce28f8cf4dec56bf65fa2e6da0cf329ec55)
 - [x] ~`saturating_neg` is only implemented on [signed integer types](https://doc.rust-lang.org/std/?search=saturating_n)~
 - [x] Is the implementation copied over from the `Wrapping`-type correct for `Saturating`?
   - [x] `Saturating::rotate_left`
   - [x] `Saturating::rotate_right`
   - [x] `Not`
   - [x] `BitXorOr` and `BitXorOrAssign`
   - [x] `BitOr` and `BitOrAssign`
   - [x] `BitAnd` and `BitAndAssign`
   - [x] `Saturating::swap_bytes`
   - [x] `Saturating::reverse_bits`
Diffstat (limited to 'library/std')
-rw-r--r--library/std/src/lib.rs2
-rw-r--r--library/std/src/num.rs2
2 files changed, 4 insertions, 0 deletions
diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs
index 5e91a0cdbd6..028a066b5a1 100644
--- a/library/std/src/lib.rs
+++ b/library/std/src/lib.rs
@@ -310,6 +310,8 @@
 #![feature(ptr_internals)]
 #![feature(rustc_attrs)]
 #![feature(rustc_private)]
+#![feature(saturating_div)]
+#![feature(saturating_int_impl)]
 #![feature(slice_concat_ext)]
 #![feature(slice_internals)]
 #![feature(slice_ptr_get)]
diff --git a/library/std/src/num.rs b/library/std/src/num.rs
index e7051f0ce95..46064bd2837 100644
--- a/library/std/src/num.rs
+++ b/library/std/src/num.rs
@@ -12,6 +12,8 @@ mod tests;
 #[cfg(test)]
 mod benches;
 
+#[unstable(feature = "saturating_int_impl", issue = "87920")]
+pub use core::num::Saturating;
 #[stable(feature = "rust1", since = "1.0.0")]
 pub use core::num::Wrapping;
 #[stable(feature = "rust1", since = "1.0.0")]