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

Into i64 #271

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Into i64 #271

wants to merge 2 commits into from

Conversation

Pat-Lafon
Copy link
Contributor

I wanted to concertize my idea from #270 into some code. Instead of creating additional from_i* methods I propose using Into<i64> for from_i64. Leveraging the trait system here runs into some non-obvious issues.

  • One probably can't implement from_u64 with Into<u64>. Well, it's allowed but then calling Int::from_u64(1) is a typing error because the type of 1 here is ambigious(under-constrained). When an integer literal has an ambigious type, it defaults to i32 and therefore fails. This is fine for Into<i64> since i32 implements Into<i64>
  • It's rather non-trivial to try to write something like impl<'ctx, T: Into<i64>> Div<T> for Int<'ctx> { because there are other implementations of Div for Int<'ctx> that the compiler can't prove to not overlap(either currently or in some future version which would lead to breakage). Maybe there is something I'm missing or some kind of nightly negative trait impls that one could use. ops.rs already heavily makes use of macros so I figure it's find to make a new macro that generalizes over the valid integer types: u64, i64, i32, i16, i8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant