Comment

Comment by zZorgz

As others mentioned, it looks equivalent to using the try! macro (which I'm not sure this is supposed to replace?)

Another sane alternative here is using and_then, map, etc.

Writing from memory too:

  fn h() -> Result<(A, B), E> {
    f().and_then(|x| g().map(|y| (x, y)))
  }
..which seems to be a different style of control flow to choose from. On one hand, I suppose one may avoid using and_then with code dealing with side effects. On another hand, ? seems restricted to being used inside functions that have to return a a single type (like Result) they operate on.
parent zZorgz 9 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton