From 9461cd84f2419a3e645412156f3bf0f01d21542f Mon Sep 17 00:00:00 2001 From: Clar Charr Date: Mon, 19 Feb 2018 15:05:11 -0500 Subject: [PATCH 1/3] Add is_one. --- src/identities.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/identities.rs b/src/identities.rs index 14f5ac06..0158a465 100644 --- a/src/identities.rs +++ b/src/identities.rs @@ -79,6 +79,14 @@ pub trait One: Sized + Mul { /// `static mut`s. // FIXME (#5527): This should be an associated constant fn one() -> Self; + + /// Returns `true` if `self` is equal to the multiplicative identity. + /// + /// Compatibility note: this method will be a requirement to implement in the future; new + /// implementors should provide it for future-compatibility. + fn is_one(&self) -> bool where Self: PartialEq { + *self == Self::one() + } } macro_rules! one_impl { From 45856ee84666449a7cbd80712edf459b44123909 Mon Sep 17 00:00:00 2001 From: Clar Charr Date: Fri, 23 Feb 2018 17:21:47 -0500 Subject: [PATCH 2/3] Make doc comment less scary. --- src/identities.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/identities.rs b/src/identities.rs index 0158a465..c8aeacf2 100644 --- a/src/identities.rs +++ b/src/identities.rs @@ -82,8 +82,9 @@ pub trait One: Sized + Mul { /// Returns `true` if `self` is equal to the multiplicative identity. /// - /// Compatibility note: this method will be a requirement to implement in the future; new - /// implementors should provide it for future-compatibility. + /// 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. fn is_one(&self) -> bool where Self: PartialEq { *self == Self::one() } From 51dad501aabddc6a84ff2d1a65fb345aac7b45ca Mon Sep 17 00:00:00 2001 From: Clar Charr Date: Fri, 23 Feb 2018 17:44:07 -0500 Subject: [PATCH 3/3] Add #[inline] to is_one. --- src/identities.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/identities.rs b/src/identities.rs index c8aeacf2..3306e5fd 100644 --- a/src/identities.rs +++ b/src/identities.rs @@ -85,6 +85,7 @@ pub trait One: Sized + Mul { /// 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() }