Git Product home page Git Product logo

Comments (4)

newpavlov avatar newpavlov commented on June 10, 2024

Why not simply use getrandom(buf).unwrap()? It's 2 characters shorter than getrandom_infallible(buf). Alternatively soon you could use OsRng.fill_bytes(buf).

I guess we could include a wrapper function (with a better name), but personally I prefer the current simple API which does not hide possibility of errors. Though if @dhardy would prefer to add such function I will not be against doing it.

from getrandom.

alex avatar alex commented on June 10, 2024

I used expect() instead of unwrap(), and eyah, it works great!

I didn't really have a use case for actually handling the error in any of my code, so I figured I should file this. If there's no interest that's ok by me!

from getrandom.

dhardy avatar dhardy commented on June 10, 2024

I believe the only reason not to use unwrap if you don't plan on returning an error value is because it merely uses a generic error message. But getting a backtrace from a panic is quite easy.

For better formatting you could do something like .unwrap_or_else(|e| panic!("{}", e)). We could add a method for this, but I don't see very much value?

from getrandom.

newpavlov avatar newpavlov commented on June 10, 2024

I think we can close this issue?

from getrandom.

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.