mhogrefe / malachite

An arbitrary-precision arithmetic library for Rust.
GNU Lesser General Public License v3.0
448 stars 17 forks source link

Natural to primitive conversion #36

Open amamic1803 opened 7 months ago

amamic1803 commented 7 months ago

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 commented 7 months ago

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 commented 7 months ago

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?