Hacker Newsnew | comments | show | ask | jobs | submit login

>I couldn't get used to the restrictions coming from not having exceptions or early function returns

I'm probably being getting confused about what you mean here, but I thought you can return from anywhere in a function in rust using 'return'. I think Option types are one way to propagate errors back up the stack (with the compiler forcing you to handle them), but I don't know how practical that is in reality.

I agree that Rust isn't ready for production use though, even in the few weeks I've been trying it they have decided to change parts of the language. Also the standard library is lacking in documentation and is pretty inconsistent.

What I mean is that if you don't have exceptions and `return` returns only from a given block, it takes some serious exercise to break out of a "fn ... { ...each { ... match ... } } }".

Return will only return from one of them, so to signal an error from the match block, you need to:

- save the result in a mutable variable in a function

- do something that results in "false" returned from each block

- return the result from the function (probably casting mut->immut on the way)

What I'd really like is either a stack unwinding exception, or a `return` keyword that's different from the "last expression in a block" syntax. Last expression could give a result for a closure, match, if, etc. while `return` could always break out of a function. For example (pseudo-code, proper syntax doesn't matter here):

    fn parse_into_list(s: &str) -> Option<Stuff> {
        let res = do s.map |c| {
            match c {
                bad_character => return None
Instead of:

    fn parse_into_list(s: &str) -> Option<Stuff> {
        let mut result: ...;
        let mut correct: true;
        do s.each |c| {
            match c {
                bad_character => {correct = false; false}
                good_character => { do_stuff_with_result; true}
        if correct {
        } else {


Applications are open for YC Winter 2016

Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | DMCA | Apply to YC | Contact