-
Notifications
You must be signed in to change notification settings - Fork 141
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add inplace methods to Zero
and One
#104
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the idea, but not the name. Usually to_X()
would be an immutable &self
method returning a derived value. Since you've documented these as "Sets self
to ...", I think set_zero
and set_one
would be better names. Another option with Rust precedent is make_zero
and make_one
.
@cuviper I looked at the guidelines and think that |
I also changed the functions to not return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, just going to remove one stale comment.
src/identities.rs
Outdated
@@ -20,6 +19,12 @@ pub trait Zero: Sized + Add<Self, Output = Self> { | |||
// This cannot be an associated constant, because of bignums. | |||
fn zero() -> Self; | |||
|
|||
/// Sets `self` to the additive identity element of `Self`, `0`. | |||
/// Returns `&mut self` to enable method chaining. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// Returns `&mut self` to enable method chaining. |
bors r+ |
104: Add inplace methods to `Zero` and `One` r=cuviper a=lcnr Adds the following default implemented methods to `Zero` and `One`: ```rust fn set_zero(&mut self) { *self = Zero::zero(); } ``` ```rust fn set_one(&mut self) { *self = One::one(); } ``` This allows for reuse of BigNums. Co-authored-by: lcnr/Bastian Kauschke <bastian_kauschke@hotmail.de> Co-authored-by: Josh Stone <cuviper@gmail.com>
Build succeeded |
Adds the following default implemented methods to
Zero
andOne
:This allows for reuse of BigNums.