소스 검색

Merge #39

39: Add is_one. r=cuviper a=clarcharr

Implements the version recommended in #5. That issue should remain open to track the breaking-change version.
bors[bot] 7 년 전
부모
커밋
3431da80a2
1개의 변경된 파일10개의 추가작업 그리고 0개의 파일을 삭제
  1. 10 0
      src/identities.rs

+ 10 - 0
src/identities.rs

@@ -79,6 +79,16 @@ pub trait One: Sized + Mul<Self, Output = Self> {
     /// `static mut`s.
     // FIXME (#5527): This should be an associated constant
     fn one() -> Self;
+
+    /// Returns `true` if `self` is equal to the multiplicative identity.
+    ///
+    /// For performance reasons, it's best to implement this manually.
+    /// After a semver bump, this method will be required, and the
+    /// `where Self: PartialEq` bound will be removed.
+    #[inline]
+    fn is_one(&self) -> bool where Self: PartialEq {
+        *self == Self::one()
+    }
 }
 
 macro_rules! one_impl {