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

Ability to create const BigUint etc. #285

Open
junderw opened this issue Sep 27, 2023 · 2 comments · May be fixed by #286
Open

Ability to create const BigUint etc. #285

junderw opened this issue Sep 27, 2023 · 2 comments · May be fixed by #286

Comments

@junderw
Copy link

junderw commented Sep 27, 2023

Instead of a Vec<u64> using a Cow<'static, [u64]> would enable people to create a const BigUint by just passing in a &'static [u64].

Due to the nature of bigints I tend to see people creating a bunch of constant values at runtime.

Sure, it's not really that expensive, but it would be nice.

@cuviper
Copy link
Member

cuviper commented Oct 27, 2023

Your edit from u32 to u64 here is revealing, because we don't make the BigDigit type alias public, and it's different between targets! It currently follows the target pointer width, but that's not an API commitment either. So I think there's not much we could put in our public API that would take advantage of Cow::Borrowed slices.

Alternatively, I started playing with a custom enum approach, where it stores either a single inline digit or a Vec as usual. This seems to work pretty well!

https://github.com/rust-num/num-bigint/compare/master..cuviper:num-bigint:enum

@cuviper
Copy link
Member

cuviper commented May 10, 2024

I've now posted mine as #307.

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 a pull request may close this issue.

2 participants