Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Bignum arithmetic actually is pretty simple in Rust if you use the right library. Rug[0] makes using bignums look almost just like using native numbers through operator overloading.

[0] https://crates.io/crates/rug



The operator overloading is nice but you still get smacked in the face right away by the borrow checker. Simple stuff like this won't compile ("use of moved value"):

    let a = Integer::from(10);
    let b = a + a;


This would work if `Integer` would implement the `Copy` trait. But I guess that type is heavy enough for it to be too expensive, therefore forcing you to explicitly call `clone()`.


That `Integer` type can't implement `Copy` because it manages a resource, meaning you can't just do a simple memcpy of the type.


  let b = &a + &a;
will work, but I agree it's unfortunate that this is necessary.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: