macro_rules! impl_common {
($num:ty) => {
#[inline]
#[must_use]
pub const fn inner(&self) -> $num {
self.0
}
}
}
pub(super) use impl_common;
macro_rules! impl_const {
() => {
#[inline]
#[must_use]
pub const fn as_str(&self) -> &str {
self.1.as_str()
}
#[inline]
#[must_use]
pub const fn as_bytes(&self) -> &[u8] {
self.1.as_bytes()
}
#[inline]
#[must_use]
#[allow(clippy::len_without_is_empty)]
pub const fn len(&self) -> usize {
self.1.len()
}
#[inline]
#[must_use]
pub const fn len_u8(&self) -> u8 {
self.1.len_u8()
}
}
}
pub(crate) use impl_const;
macro_rules! impl_not_const {
() => {
#[inline]
#[must_use]
pub fn as_str(&self) -> &str {
self.1.as_str()
}
#[inline]
#[must_use]
pub fn as_bytes(&self) -> &[u8] {
self.1.as_bytes()
}
#[inline]
#[must_use]
pub fn len(&self) -> usize {
self.1.len()
}
#[inline]
#[must_use]
pub fn is_empty(&self) -> bool {
self.1.is_empty()
}
}
}
pub(crate) use impl_not_const;
macro_rules! impl_usize {
() => {
#[inline]
#[cfg(target_pointer_width = "64")]
#[must_use]
pub const fn usize(&self) -> usize {
self.0 as usize
}
}
}
pub(crate) use impl_usize;
macro_rules! impl_isize {
() => {
#[inline]
#[cfg(target_pointer_width = "64")]
#[must_use]
pub const fn isize(&self) -> isize {
self.0 as isize
}
}
}
pub(crate) use impl_isize;
macro_rules! impl_traits {
($s:ty, $num:ty) => {
impl std::ops::Deref for $s {
type Target = str;
#[inline]
fn deref(&self) -> &Self::Target {
self.as_str()
}
}
impl AsRef<str> for $s {
#[inline]
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl AsRef<[u8]> for $s {
#[inline]
fn as_ref(&self) -> &[u8] {
self.as_bytes()
}
}
impl std::borrow::Borrow<str> for $s {
#[inline]
fn borrow(&self) -> &str {
self.as_str()
}
}
impl std::fmt::Display for $s {
#[inline]
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "{}", &self.1.as_str())
}
}
impl std::default::Default for $s {
#[inline]
fn default() -> Self {
Self::ZERO
}
}
impl PartialEq<&$s> for $s {
#[inline]
fn eq(&self, other: &&$s) -> bool {
self == other
}
}
impl PartialEq<$s> for &$s {
#[inline]
fn eq(&self, other: &$s) -> bool {
self == other
}
}
impl PartialEq<str> for $s {
#[inline]
fn eq(&self, other: &str) -> bool {
self.1.as_str() == other
}
}
impl PartialEq<$s> for str {
#[inline]
fn eq(&self, other: &$s) -> bool {
self == other.1.as_str()
}
}
impl PartialEq<&str> for $s {
#[inline]
fn eq(&self, other: &&str) -> bool {
&self.1.as_str() == other
}
}
impl PartialEq<&$s> for str {
#[inline]
fn eq(&self, other: &&$s) -> bool {
self == other.1.as_str()
}
}
impl PartialEq<$num> for $s {
#[inline]
fn eq(&self, other: &$num) -> bool {
self.0 == *other
}
}
impl PartialEq<$s> for $num {
#[inline]
fn eq(&self, other: &$s) -> bool {
*self == other.0
}
}
impl PartialEq<$num> for &$s {
#[inline]
fn eq(&self, other: &$num) -> bool {
self.0 == *other
}
}
impl PartialEq<&$s> for $num {
#[inline]
fn eq(&self, other: &&$s) -> bool {
*self == other.0
}
}
impl PartialOrd<str> for $s {
#[inline]
fn partial_cmp(&self, other: &str) -> Option<std::cmp::Ordering> {
Some(self.1.as_str().cmp(other))
}
}
impl PartialOrd<$s> for str {
#[inline]
fn partial_cmp(&self, other: &$s) -> Option<std::cmp::Ordering> {
Some(self.cmp(other.1.as_str()))
}
}
impl PartialOrd<&str> for $s {
#[inline]
fn partial_cmp(&self, other: &&str) -> Option<std::cmp::Ordering> {
Some(self.1.as_str().cmp(other))
}
}
impl PartialOrd<&$s> for str {
#[inline]
fn partial_cmp(&self, other: &&$s) -> Option<std::cmp::Ordering> {
Some(self.cmp(other.1.as_str()))
}
}
impl PartialOrd<$num> for $s {
#[inline]
fn partial_cmp(&self, other: &$num) -> Option<std::cmp::Ordering> {
self.0.partial_cmp(other)
}
}
impl PartialOrd<$s> for $num {
#[inline]
fn partial_cmp(&self, other: &$s) -> Option<std::cmp::Ordering> {
self.partial_cmp(&other.0)
}
}
impl PartialOrd<$num> for &$s {
#[inline]
fn partial_cmp(&self, other: &$num) -> Option<std::cmp::Ordering> {
self.0.partial_cmp(other)
}
}
impl PartialOrd<&$s> for $num {
#[inline]
fn partial_cmp(&self, other: &&$s) -> Option<std::cmp::Ordering> {
self.partial_cmp(&other.0)
}
}
}
}
pub(crate) use impl_traits;
macro_rules! impl_impl_math {
($trait_word:ident, $operator:tt, $s:ty, $num:ty) => {
paste::paste! {
impl std::ops::[<$trait_word>]<$s> for $s {
type Output = Self;
#[inline]
fn [<$trait_word:lower>](self, other: $s) -> Self {
let r = self.inner() $operator other.inner();
Self::from(r)
}
}
impl std::ops::[<$trait_word>]<$num> for $s {
type Output = Self;
#[inline]
fn [<$trait_word:lower>](self, other: $num) -> Self {
Self::from(self.inner() $operator other)
}
}
impl std::ops::[<$trait_word>]<$s> for $num {
type Output = Self;
#[inline]
fn [<$trait_word:lower>](self, other: $s) -> Self {
Self::from(self $operator other.inner())
}
}
impl std::ops::[<$trait_word>]<&$s> for $s {
type Output = Self;
#[inline]
fn [<$trait_word:lower>](self, other: &$s) -> Self {
Self::from(self.inner() $operator other.inner())
}
}
impl std::ops::[<$trait_word>]<&$num> for $s {
type Output = Self;
#[inline]
fn [<$trait_word:lower>](self, other: &$num) -> Self {
Self::from(self.inner() $operator other)
}
}
impl std::ops::[<$trait_word>]<&$s> for $num {
type Output = Self;
#[inline]
fn [<$trait_word:lower>](self, other: &$s) -> Self {
Self::from(self $operator other.inner())
}
}
}
}
}
pub(crate) use impl_impl_math;
macro_rules! impl_math {
($s:ty, $num:ty) => {
impl_impl_math!(Add, +, $s, $num);
impl_impl_math!(Sub, -, $s, $num);
impl_impl_math!(Div, /, $s, $num);
impl_impl_math!(Mul, *, $s, $num);
impl_impl_math!(Rem, %, $s, $num);
}
}
pub(crate) use impl_math;
macro_rules! return_bad_float {
($float:ident, $nan:expr, $infinite:expr) => {
match $float.classify() {
std::num::FpCategory::Normal => (),
std::num::FpCategory::Nan => return $nan,
std::num::FpCategory::Infinite => return $infinite,
_ => (),
}
}
}
pub(crate) use return_bad_float;
macro_rules! str_u64 {
($number:expr) => {{
$crate::num::Unsigned::from_priv_inner($number).as_str()
}}
}
pub(crate) use str_u64;
macro_rules! str_i64 {
($number:expr) => {{
$crate::num::Int::from_priv_inner($number).as_str()
}}
}
pub(crate) use str_i64;
macro_rules! handle_over_u32 {
($value:expr, $type:ty) => {
if $value > (u32::MAX as $type) {
return Self::UNKNOWN;
}
};
}
pub(crate) use handle_over_u32;