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

Natural to primitive conversion #36

Open
amamic1803 opened this issue Feb 12, 2024 · 2 comments
Open

Natural to primitive conversion #36

amamic1803 opened this issue Feb 12, 2024 · 2 comments

Comments

@amamic1803
Copy link
Contributor

Hi,
is there a way to convert Natural to primitive integer, like u64 without adding malachite_base as dependency? I've looked at malachite::natural::conversion::primitive_int_from_natural module, but there doesn't seem to be any trait implementations I can import. Examples use trait implementations from malachite_base.
Thanks

@mhogrefe
Copy link
Owner

mhogrefe commented Feb 12, 2024

You should be able to use TryFrom: https://docs.rs/malachite-nz/latest/malachite_nz/natural/struct.Natural.html#impl-TryFrom%3C%26Natural%3E-for-u64.

But the purpose of malachite_base is to support the other Malachite crates, so in general there will be many dependencies on it.

@amamic1803
Copy link
Contributor Author

I understand that malachite crate just exports stuff from these malachite-nz, malachite-base, ... crates and that just using malachite as dependency also pulls those crates, but I don't understand why I can't just use conversion on Natural type directly from malachite but have to do it from malachite-nz. From what I can tell malachite just exports Natural from malachite-nz, but in the docs on malachite there are no TryFrom Natural for primitive integers like there are in docs for Natural in malachite-nz (that you linked). I am looking at docs for v0.4.4, since v0.4.5 docs aren't available, but I also tried building them locally for v0.4.5 and there also aren't implementations for TryFrom Natural for natural exported in malachite, but there are those for Natural in malachite-nz.

It seems to me that these implementations of TryFrom should also be exported into malachite from malachite-nz, but for some reason that is not happening. Is it maybe a bug?

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

No branches or pull requests

2 participants