Skip to content
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

Feature request: can we have a trait for checked_add_signed uX implementations? #302

Open
SET001 opened this issue Dec 11, 2023 · 0 comments

Comments

@SET001
Copy link

SET001 commented Dec 11, 2023

all uX and iX types implements checked_add_signed and it would be handy to have a trait as marker for such types:

pub trait CheckedAddSigned
where
  Self: Sized,
{
  type RHS: TryFrom<i32>;
  fn checked_add_signed(self, rhs: Self::RHS) -> Option<Self>;
}

macro_rules! impl_checked_add_signed {
  ($t:ident, $rhs:ident) => {
    impl CheckedAddSigned for $t {
      type RHS = $rhs;
      fn checked_add_signed(self, rhs: Self::RHS) -> Option<Self> {
        Self::checked_add_signed(self, rhs)
      }
    }
  };
}

impl_checked_add_signed!(u8, i8);
impl_checked_add_signed!(u16, i16);
impl_checked_add_signed!(u32, i32);
impl_checked_add_signed!(u64, i64);
impl_checked_add_signed!(usize, isize);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants