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

It would be inlined by the compiler, and the standard library could introduce a macro to eliminate the awkward code.

    try!({
      let db = pgsql.connect(localhost)?
      let stmt = db.prepare("INSERT INTO log VALUES(?,?)")?
      stmt.execute(("debug", "Note to self: debug logs are noncritical"))?
    } catch err: DatabaseError {
      println!("Could not write log to database {}", err);
    })
===>

    match (|| {
      let db = pgsql.connect(localhost)?
      let stmt = db.prepare("INSERT INTO log VALUES(?,?)")?
      stmt.execute(("debug", "Note to self: debug logs are noncritical"))?
    }) {
      Document(d) => d,
      DatabaseError(err) => println!("Could not write log to database {}", err)
    }


Closures aren't "free", you need to structure your code around being unable to return/break/continue across the closure boundary, and there's probably some silly borrow checker errors involved too.




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

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

Search: