]> git.lizzy.rs Git - rust.git/commitdiff
implement IsZero for Saturating and Wrapping
authorasquared31415 <34665709+asquared31415@users.noreply.github.com>
Fri, 2 Sep 2022 22:53:20 +0000 (18:53 -0400)
committerasquared31415 <34665709+asquared31415@users.noreply.github.com>
Fri, 2 Sep 2022 23:55:01 +0000 (19:55 -0400)
library/alloc/src/lib.rs
library/alloc/src/vec/is_zero.rs

index ad6d19bbc6875203d6e721d85be0d53684e4048a..e5cf9033c86033caebd75a01cc3c6f54ebb55054 100644 (file)
 #![feature(ptr_metadata)]
 #![feature(ptr_sub_ptr)]
 #![feature(receiver_trait)]
+#![feature(saturating_int_impl)]
 #![feature(set_ptr_value)]
 #![feature(slice_from_ptr_range)]
 #![feature(slice_group_by)]
index 92a32779b8e64b4866e0fb9a9707b10a51c6c261..2e025c8a4a5d3fd843cbbbab43e3dd9c8533ab3d 100644 (file)
@@ -1,3 +1,5 @@
+use core::num::{Saturating, Wrapping};
+
 use crate::boxed::Box;
 
 #[rustc_specialization_trait]
@@ -144,3 +146,17 @@ fn is_zero(&self) -> bool {
     NonZeroUsize,
     NonZeroIsize,
 );
+
+unsafe impl<T: IsZero> IsZero for Wrapping<T> {
+    #[inline]
+    fn is_zero(&self) -> bool {
+        self.0.is_zero()
+    }
+}
+
+unsafe impl<T: IsZero> IsZero for Saturating<T> {
+    #[inline]
+    fn is_zero(&self) -> bool {
+        self.0.is_zero()
+    }
+}