-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement bool logic operations and move them to StrongNumericType (#15)
- Loading branch information
1 parent
056b160
commit f82e8be
Showing
6 changed files
with
204 additions
and
27 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 |
---|---|---|
@@ -0,0 +1,154 @@ | ||
use proc_macro2::TokenStream; | ||
use quote::quote; | ||
|
||
pub(crate) fn implement_bool_ops(name: &syn::Ident) -> TokenStream { | ||
quote! { | ||
impl std::ops::Not for #name { | ||
type Output = Self; | ||
|
||
fn not(self) -> Self::Output { | ||
Self::new(!self.value()) | ||
} | ||
} | ||
|
||
impl std::ops::Not for &#name { | ||
type Output = #name; | ||
|
||
fn not(self) -> Self::Output { | ||
#name::new(!self.value()) | ||
} | ||
} | ||
|
||
impl std::ops::BitAnd<Self> for #name { | ||
type Output = Self; | ||
|
||
fn bitand(self, rhs: Self) -> Self::Output { | ||
Self::new(self.value() & rhs.value()) | ||
} | ||
} | ||
|
||
impl std::ops::BitAnd<&Self> for #name { | ||
type Output = Self; | ||
|
||
fn bitand(self, rhs: &Self) -> Self::Output { | ||
Self::new(self.value() & rhs.value()) | ||
} | ||
} | ||
|
||
impl std::ops::BitAnd<#name> for &#name { | ||
type Output = #name; | ||
|
||
fn bitand(self, rhs: #name) -> Self::Output { | ||
#name::new(self.value() & rhs.value()) | ||
} | ||
} | ||
|
||
impl std::ops::BitAnd<&#name> for &#name { | ||
type Output = #name; | ||
|
||
fn bitand(self, rhs: &#name) -> Self::Output { | ||
#name::new(self.value() & rhs.value()) | ||
} | ||
} | ||
|
||
impl std::ops::BitAndAssign<Self> for #name { | ||
fn bitand_assign(&mut self, rhs: Self) { | ||
self.0 &= rhs.value() | ||
} | ||
} | ||
|
||
impl std::ops::BitAndAssign<&Self> for #name { | ||
fn bitand_assign(&mut self, rhs: &Self) { | ||
self.0 &= rhs.value() | ||
} | ||
} | ||
|
||
impl std::ops::BitOr<Self> for #name { | ||
type Output = Self; | ||
|
||
fn bitor(self, rhs: Self) -> Self::Output { | ||
Self::new(self.value() | rhs.value()) | ||
} | ||
} | ||
|
||
impl std::ops::BitOr<&Self> for #name { | ||
type Output = Self; | ||
|
||
fn bitor(self, rhs: &Self) -> Self::Output { | ||
Self::new(self.value() | rhs.value()) | ||
} | ||
} | ||
|
||
impl std::ops::BitOr<#name> for &#name { | ||
type Output = #name; | ||
|
||
fn bitor(self, rhs: #name) -> Self::Output { | ||
#name::new(self.value() | rhs.value()) | ||
} | ||
} | ||
|
||
impl std::ops::BitOr<&#name> for &#name { | ||
type Output = #name; | ||
|
||
fn bitor(self, rhs: &#name) -> Self::Output { | ||
#name::new(self.value() | rhs.value()) | ||
} | ||
} | ||
|
||
impl std::ops::BitOrAssign<Self> for #name { | ||
fn bitor_assign(&mut self, rhs: Self) { | ||
self.0 |= rhs.value() | ||
} | ||
} | ||
|
||
impl std::ops::BitOrAssign<&Self> for #name { | ||
fn bitor_assign(&mut self, rhs: &Self) { | ||
self.0 |= rhs.value() | ||
} | ||
} | ||
|
||
impl std::ops::BitXor<Self> for #name { | ||
type Output = Self; | ||
|
||
fn bitxor(self, rhs: Self) -> Self::Output { | ||
Self::new(self.value() ^ rhs.value()) | ||
} | ||
} | ||
|
||
impl std::ops::BitXor<&Self> for #name { | ||
type Output = Self; | ||
|
||
fn bitxor(self, rhs: &Self) -> Self::Output { | ||
Self::new(self.value() ^ rhs.value()) | ||
} | ||
} | ||
|
||
impl std::ops::BitXor<#name> for &#name { | ||
type Output = #name; | ||
|
||
fn bitxor(self, rhs: #name) -> Self::Output { | ||
#name::new(self.value() ^ rhs.value()) | ||
} | ||
} | ||
|
||
impl std::ops::BitXor<&#name> for &#name { | ||
type Output = #name; | ||
|
||
fn bitxor(self, rhs: &#name) -> Self::Output { | ||
#name::new(self.value() ^ rhs.value()) | ||
} | ||
} | ||
|
||
impl std::ops::BitXorAssign<Self> for #name { | ||
fn bitxor_assign(&mut self, rhs: Self) { | ||
self.0 ^= rhs.value() | ||
} | ||
} | ||
|
||
impl std::ops::BitXorAssign<&Self> for #name { | ||
fn bitxor_assign(&mut self, rhs: &Self) { | ||
self.0 ^= rhs.value() | ||
} | ||
} | ||
} | ||
} |
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 was deleted.
Oops, something went wrong.
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