Code Monkey home page Code Monkey logo

Comments (7)

cuviper avatar cuviper commented on May 28, 2024

I think std::convert::From is the right trait for lossless conversions. But we can't implement that in num except for our own types, like for BigInt/BigUint in #117. Maybe you should propose adding primitive From impls in rust proper?

from num.

cuviper avatar cuviper commented on May 28, 2024

BTW, nice graph!

You might simplify it a bit by leaving it implicit for transitive conversions. That is, if A->B and B->C, then implicitly A->C. Hmm, I wonder if a generic impl can express that, something like:

impl<A, B: From<A>, C: From<B>> From<A> for C {
    fn from(a: A) -> C { C::from(B::from(a)) }
}

But the existence of impl<T> From<T> for T might make this explode...

(don't mind me, just musing...)

from num.

bluss avatar bluss commented on May 28, 2024

Maybe the conv crate covers this appropriately now.

from num.

cuviper avatar cuviper commented on May 28, 2024

Does conv have any new infallible conversions? I only see ConvUtil::into_as which is using the standard Into trait anyway.

But I noticed nightly From does now document integer upcasts -- this was merged only 2 days ago in rust-lang/rust#28921! So if you submit a similar addition for floats, you'll be done here. (If you don't want to, let me know and maybe I'll try it.)

from num.

bluss avatar bluss commented on May 28, 2024

Nice! I had missed that. Please do if you want to!

from num.

cuviper avatar cuviper commented on May 28, 2024

The float conversions are now merged! I think there's nothing else to do here.

from num.

bluss avatar bluss commented on May 28, 2024

Nice!

from num.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.