-
Notifications
You must be signed in to change notification settings - Fork 115
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
Allow creating Int from i32 #270
base: master
Are you sure you want to change the base?
Conversation
What about converting |
Sure, if that's feasible it would definitely work. :-) My rust knowledge is a bit limited though, and I couldn't figure out how to make it work with the |
Hmmm, this is doable except that there needs to have extra handling for the impl's because It's a bit hacky to work around, maybe leveraging macro_rules! impl_binary_op_number_raw {
($ty:ty, $other:ty, $other_fn:ident, $output:ty, $base_trait:ident, $base_fn:ident, $function:ident, $construct_constant:ident) => {
- impl<'ctx> $base_trait<$other> for $ty {
+ impl<'ctx, T : Into<$other>> $base_trait<T> for $ty {
type Output = $output;
- fn $base_fn(self, rhs: $other) -> Self::Output {
+ fn $base_fn(self, rhs: T) -> Self::Output {
let c;
- $construct_constant!(c, $other_fn, rhs, self);
+ $construct_constant!(c, $other_fn, rhs.into(), self);
$base_trait::$base_fn(self, c)
}
} |
Maybe there's room here to use |
Sort of? So
I think this is akin to https://stackoverflow.com/questions/39159226/conflicting-implementations-of-trait-in-rust. I think if they were impl<'ctx, T: Into<i64> + num_traits::Signed> Div<T> for Int<'ctx> {
type Output = Int<'ctx>;
fn div(self, rhs: T) -> Self::Output {
let c;
c = Int::from_i64(self.get_ctx(), (rhs.into()));
Div::div(self, c)
}
}
impl<'ctx, T: Into<u64> + num_traits::Unsigned> Div<T> for Int<'ctx> {
type Output = Int<'ctx>;
fn div(self, rhs: T) -> Self::Output {
let c;
c = Int::from_u64(self.get_ctx(), (rhs.into()));
Div::div(self, c)
}
} |
Hi,
Thank you for the neat package. I've been a long time user of Z3 through Python, and am now looking into switching to Rust for more performance. One hurdle I encountered is mathematical operations with
Int
and i32. E.g., I would like to do the following:This would fail, because by default integers in Rust are i32 and
ast::Int
can currently only be created from i64 or u64. As constantly writingas i64
is tedious, I open this MR to (1) allow generatingast::Int
from i32, and (2) to support automatically converting i32 to Int in binops.Implementation-wise, it's really nothing special: cast the i32 to i64 and use
from_i64
. Not sure if this fits within the Rust ideology, but from Z3's point of view it doesn't matter anyway. Is this something that would be useful?