-
Notifications
You must be signed in to change notification settings - Fork 242
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# Description ## Problem\* Part of #4845 ## Summary\* This PR splits the `ops` module into `arith` and `bit` submodules similarly to the Rust stdlib. ## Additional Context ## Documentation\* Check one: - [x] No documentation needed. - [ ] Documentation included in this PR. - [ ] **[For Experimental Features]** Documentation to be submitted in a separate PR. # PR Checklist\* - [x] I have tested the changes locally. - [x] I have formatted the changes with [Prettier](https://prettier.io/) and/or `cargo fmt` on default settings.
- Loading branch information
1 parent
9f2c21d
commit a1a2afb
Showing
5 changed files
with
187 additions
and
182 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,170 +1,5 @@ | ||
// docs:start:add-trait | ||
trait Add { | ||
fn add(self, other: Self) -> Self; | ||
} | ||
// docs:end:add-trait | ||
|
||
impl Add for Field { fn add(self, other: Field) -> Field { self + other } } | ||
|
||
impl Add for u64 { fn add(self, other: u64) -> u64 { self + other } } | ||
impl Add for u32 { fn add(self, other: u32) -> u32 { self + other } } | ||
impl Add for u8 { fn add(self, other: u8) -> u8 { self + other } } | ||
|
||
impl Add for i8 { fn add(self, other: i8) -> i8 { self + other } } | ||
impl Add for i32 { fn add(self, other: i32) -> i32 { self + other } } | ||
impl Add for i64 { fn add(self, other: i64) -> i64 { self + other } } | ||
|
||
// docs:start:sub-trait | ||
trait Sub { | ||
fn sub(self, other: Self) -> Self; | ||
} | ||
// docs:end:sub-trait | ||
|
||
impl Sub for Field { fn sub(self, other: Field) -> Field { self - other } } | ||
|
||
impl Sub for u64 { fn sub(self, other: u64) -> u64 { self - other } } | ||
impl Sub for u32 { fn sub(self, other: u32) -> u32 { self - other } } | ||
impl Sub for u8 { fn sub(self, other: u8) -> u8 { self - other } } | ||
|
||
impl Sub for i8 { fn sub(self, other: i8) -> i8 { self - other } } | ||
impl Sub for i32 { fn sub(self, other: i32) -> i32 { self - other } } | ||
impl Sub for i64 { fn sub(self, other: i64) -> i64 { self - other } } | ||
|
||
// docs:start:mul-trait | ||
trait Mul { | ||
fn mul(self, other: Self) -> Self; | ||
} | ||
// docs:end:mul-trait | ||
|
||
impl Mul for Field { fn mul(self, other: Field) -> Field { self * other } } | ||
|
||
impl Mul for u64 { fn mul(self, other: u64) -> u64 { self * other } } | ||
impl Mul for u32 { fn mul(self, other: u32) -> u32 { self * other } } | ||
impl Mul for u8 { fn mul(self, other: u8) -> u8 { self * other } } | ||
|
||
impl Mul for i8 { fn mul(self, other: i8) -> i8 { self * other } } | ||
impl Mul for i32 { fn mul(self, other: i32) -> i32 { self * other } } | ||
impl Mul for i64 { fn mul(self, other: i64) -> i64 { self * other } } | ||
|
||
// docs:start:div-trait | ||
trait Div { | ||
fn div(self, other: Self) -> Self; | ||
} | ||
// docs:end:div-trait | ||
|
||
impl Div for Field { fn div(self, other: Field) -> Field { self / other } } | ||
|
||
impl Div for u64 { fn div(self, other: u64) -> u64 { self / other } } | ||
impl Div for u32 { fn div(self, other: u32) -> u32 { self / other } } | ||
impl Div for u8 { fn div(self, other: u8) -> u8 { self / other } } | ||
|
||
impl Div for i8 { fn div(self, other: i8) -> i8 { self / other } } | ||
impl Div for i32 { fn div(self, other: i32) -> i32 { self / other } } | ||
impl Div for i64 { fn div(self, other: i64) -> i64 { self / other } } | ||
|
||
// docs:start:rem-trait | ||
trait Rem{ | ||
fn rem(self, other: Self) -> Self; | ||
} | ||
// docs:end:rem-trait | ||
|
||
impl Rem for u64 { fn rem(self, other: u64) -> u64 { self % other } } | ||
impl Rem for u32 { fn rem(self, other: u32) -> u32 { self % other } } | ||
impl Rem for u8 { fn rem(self, other: u8) -> u8 { self % other } } | ||
|
||
impl Rem for i8 { fn rem(self, other: i8) -> i8 { self % other } } | ||
impl Rem for i32 { fn rem(self, other: i32) -> i32 { self % other } } | ||
impl Rem for i64 { fn rem(self, other: i64) -> i64 { self % other } } | ||
|
||
// docs:start:neg-trait | ||
trait Neg { | ||
fn neg(self) -> Self; | ||
} | ||
// docs:end:neg-trait | ||
|
||
// docs:start:neg-trait-impls | ||
impl Neg for Field { fn neg(self) -> Field { -self } } | ||
|
||
impl Neg for i8 { fn neg(self) -> i8 { -self } } | ||
impl Neg for i32 { fn neg(self) -> i32 { -self } } | ||
impl Neg for i64 { fn neg(self) -> i64 { -self } } | ||
// docs:end:neg-trait-impls | ||
|
||
// docs:start:bitor-trait | ||
trait BitOr { | ||
fn bitor(self, other: Self) -> Self; | ||
} | ||
// docs:end:bitor-trait | ||
|
||
impl BitOr for bool { fn bitor(self, other: bool) -> bool { self | other } } | ||
|
||
impl BitOr for u64 { fn bitor(self, other: u64) -> u64 { self | other } } | ||
impl BitOr for u32 { fn bitor(self, other: u32) -> u32 { self | other } } | ||
impl BitOr for u8 { fn bitor(self, other: u8) -> u8 { self | other } } | ||
|
||
impl BitOr for i8 { fn bitor(self, other: i8) -> i8 { self | other } } | ||
impl BitOr for i32 { fn bitor(self, other: i32) -> i32 { self | other } } | ||
impl BitOr for i64 { fn bitor(self, other: i64) -> i64 { self | other } } | ||
|
||
// docs:start:bitand-trait | ||
trait BitAnd { | ||
fn bitand(self, other: Self) -> Self; | ||
} | ||
// docs:end:bitand-trait | ||
|
||
impl BitAnd for bool { fn bitand(self, other: bool) -> bool { self & other } } | ||
|
||
impl BitAnd for u64 { fn bitand(self, other: u64) -> u64 { self & other } } | ||
impl BitAnd for u32 { fn bitand(self, other: u32) -> u32 { self & other } } | ||
impl BitAnd for u8 { fn bitand(self, other: u8) -> u8 { self & other } } | ||
|
||
impl BitAnd for i8 { fn bitand(self, other: i8) -> i8 { self & other } } | ||
impl BitAnd for i32 { fn bitand(self, other: i32) -> i32 { self & other } } | ||
impl BitAnd for i64 { fn bitand(self, other: i64) -> i64 { self & other } } | ||
|
||
// docs:start:bitxor-trait | ||
trait BitXor { | ||
fn bitxor(self, other: Self) -> Self; | ||
} | ||
// docs:end:bitxor-trait | ||
|
||
impl BitXor for bool { fn bitxor(self, other: bool) -> bool { self ^ other } } | ||
|
||
impl BitXor for u64 { fn bitxor(self, other: u64) -> u64 { self ^ other } } | ||
impl BitXor for u32 { fn bitxor(self, other: u32) -> u32 { self ^ other } } | ||
impl BitXor for u8 { fn bitxor(self, other: u8) -> u8 { self ^ other } } | ||
|
||
impl BitXor for i8 { fn bitxor(self, other: i8) -> i8 { self ^ other } } | ||
impl BitXor for i32 { fn bitxor(self, other: i32) -> i32 { self ^ other } } | ||
impl BitXor for i64 { fn bitxor(self, other: i64) -> i64 { self ^ other } } | ||
|
||
// docs:start:shl-trait | ||
trait Shl { | ||
fn shl(self, other: u8) -> Self; | ||
} | ||
// docs:end:shl-trait | ||
|
||
impl Shl for u32 { fn shl(self, other: u8) -> u32 { self << other } } | ||
impl Shl for u64 { fn shl(self, other: u8) -> u64 { self << other } } | ||
impl Shl for u8 { fn shl(self, other: u8) -> u8 { self << other } } | ||
impl Shl for u1 { fn shl(self, other: u8) -> u1 { self << other } } | ||
|
||
impl Shl for i8 { fn shl(self, other: u8) -> i8 { self << other } } | ||
impl Shl for i32 { fn shl(self, other: u8) -> i32 { self << other } } | ||
impl Shl for i64 { fn shl(self, other: u8) -> i64 { self << other } } | ||
|
||
// docs:start:shr-trait | ||
trait Shr { | ||
fn shr(self, other: u8) -> Self; | ||
} | ||
// docs:end:shr-trait | ||
|
||
impl Shr for u64 { fn shr(self, other: u8) -> u64 { self >> other } } | ||
impl Shr for u32 { fn shr(self, other: u8) -> u32 { self >> other } } | ||
impl Shr for u8 { fn shr(self, other: u8) -> u8 { self >> other } } | ||
impl Shr for u1 { fn shr(self, other: u8) -> u1 { self >> other } } | ||
|
||
impl Shr for i8 { fn shr(self, other: u8) -> i8 { self >> other } } | ||
impl Shr for i32 { fn shr(self, other: u8) -> i32 { self >> other } } | ||
impl Shr for i64 { fn shr(self, other: u8) -> i64 { self >> other } } | ||
mod arith; | ||
mod bit; | ||
|
||
use arith::{Add, Sub, Mul, Div, Rem, Neg}; | ||
use bit::{BitOr, BitAnd, BitXor, Shl, Shr}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
// docs:start:add-trait | ||
trait Add { | ||
fn add(self, other: Self) -> Self; | ||
} | ||
// docs:end:add-trait | ||
|
||
impl Add for Field { fn add(self, other: Field) -> Field { self + other } } | ||
|
||
impl Add for u64 { fn add(self, other: u64) -> u64 { self + other } } | ||
impl Add for u32 { fn add(self, other: u32) -> u32 { self + other } } | ||
impl Add for u8 { fn add(self, other: u8) -> u8 { self + other } } | ||
|
||
impl Add for i8 { fn add(self, other: i8) -> i8 { self + other } } | ||
impl Add for i32 { fn add(self, other: i32) -> i32 { self + other } } | ||
impl Add for i64 { fn add(self, other: i64) -> i64 { self + other } } | ||
|
||
// docs:start:sub-trait | ||
trait Sub { | ||
fn sub(self, other: Self) -> Self; | ||
} | ||
// docs:end:sub-trait | ||
|
||
impl Sub for Field { fn sub(self, other: Field) -> Field { self - other } } | ||
|
||
impl Sub for u64 { fn sub(self, other: u64) -> u64 { self - other } } | ||
impl Sub for u32 { fn sub(self, other: u32) -> u32 { self - other } } | ||
impl Sub for u8 { fn sub(self, other: u8) -> u8 { self - other } } | ||
|
||
impl Sub for i8 { fn sub(self, other: i8) -> i8 { self - other } } | ||
impl Sub for i32 { fn sub(self, other: i32) -> i32 { self - other } } | ||
impl Sub for i64 { fn sub(self, other: i64) -> i64 { self - other } } | ||
|
||
// docs:start:mul-trait | ||
trait Mul { | ||
fn mul(self, other: Self) -> Self; | ||
} | ||
// docs:end:mul-trait | ||
|
||
impl Mul for Field { fn mul(self, other: Field) -> Field { self * other } } | ||
|
||
impl Mul for u64 { fn mul(self, other: u64) -> u64 { self * other } } | ||
impl Mul for u32 { fn mul(self, other: u32) -> u32 { self * other } } | ||
impl Mul for u8 { fn mul(self, other: u8) -> u8 { self * other } } | ||
|
||
impl Mul for i8 { fn mul(self, other: i8) -> i8 { self * other } } | ||
impl Mul for i32 { fn mul(self, other: i32) -> i32 { self * other } } | ||
impl Mul for i64 { fn mul(self, other: i64) -> i64 { self * other } } | ||
|
||
// docs:start:div-trait | ||
trait Div { | ||
fn div(self, other: Self) -> Self; | ||
} | ||
// docs:end:div-trait | ||
|
||
impl Div for Field { fn div(self, other: Field) -> Field { self / other } } | ||
|
||
impl Div for u64 { fn div(self, other: u64) -> u64 { self / other } } | ||
impl Div for u32 { fn div(self, other: u32) -> u32 { self / other } } | ||
impl Div for u8 { fn div(self, other: u8) -> u8 { self / other } } | ||
|
||
impl Div for i8 { fn div(self, other: i8) -> i8 { self / other } } | ||
impl Div for i32 { fn div(self, other: i32) -> i32 { self / other } } | ||
impl Div for i64 { fn div(self, other: i64) -> i64 { self / other } } | ||
|
||
// docs:start:rem-trait | ||
trait Rem{ | ||
fn rem(self, other: Self) -> Self; | ||
} | ||
// docs:end:rem-trait | ||
|
||
impl Rem for u64 { fn rem(self, other: u64) -> u64 { self % other } } | ||
impl Rem for u32 { fn rem(self, other: u32) -> u32 { self % other } } | ||
impl Rem for u8 { fn rem(self, other: u8) -> u8 { self % other } } | ||
|
||
impl Rem for i8 { fn rem(self, other: i8) -> i8 { self % other } } | ||
impl Rem for i32 { fn rem(self, other: i32) -> i32 { self % other } } | ||
impl Rem for i64 { fn rem(self, other: i64) -> i64 { self % other } } | ||
|
||
// docs:start:neg-trait | ||
trait Neg { | ||
fn neg(self) -> Self; | ||
} | ||
// docs:end:neg-trait | ||
|
||
// docs:start:neg-trait-impls | ||
impl Neg for Field { fn neg(self) -> Field { -self } } | ||
|
||
impl Neg for i8 { fn neg(self) -> i8 { -self } } | ||
impl Neg for i32 { fn neg(self) -> i32 { -self } } | ||
impl Neg for i64 { fn neg(self) -> i64 { -self } } | ||
// docs:end:neg-trait-impls | ||
|
Oops, something went wrong.