Giter VIP home page Giter VIP logo

Comments (6)

trevyn avatar trevyn commented on June 3, 2024 2

More concise way, that was non-obvious to me:

use anyhow::{Context, Result};

fn maybe_get() -> Option<T> {
    ...
}

fn demo() -> Result<()> {
    let t = maybe_get().context("there is no T")?;
    ...
}

from https://docs.rs/anyhow/1.0.31/anyhow/trait.Context.html#impl-Context%3CT%2C%20Infallible%3E-for-Option%3CT%3E

from anyhow.

jkelleyrtp avatar jkelleyrtp commented on June 3, 2024 1

Context is waaay better than what I've been using. Thanks!

 .ok_or(anyhow!("there is no T"))?;

vs

.context("there is no T")?;

from anyhow.

dtolnay avatar dtolnay commented on June 3, 2024

This impl wouldn't be allowed in anyhow by coherence, so we can't add this.

from anyhow.

repnop avatar repnop commented on June 3, 2024

Ah, forgot about that. Thanks for the quick response :)

from anyhow.

BlinkyStitt avatar BlinkyStitt commented on June 3, 2024

So if we can't use a From, what is the standard way to deal with an error like NoneError?

from anyhow.

BlinkyStitt avatar BlinkyStitt commented on June 3, 2024

Never mind! I think this is the common way: #35 (comment)

from anyhow.

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.