Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

What is the equivalent of 'pass' from Python, in Rust?

I want to check if the result from a request is having any issue. I categorize it into two: i) server error, ii) something else that is not a success. The third category is, result actually being a success. However, in the third category, I don’t want to do anything.

So, my desirable code is:

if res.status().is_server_error() {
        panic!("server error!");
    } else if !(res.status.is_success()){
        panic!("Something else happened. Status: {:?}", res.status());
    } else{
        pass;
    }

I am aware of other ways to achieve this result: using match, ifs instead of if else if. But I wanted to learn what is the corresponding keyword of pass, like we have in Python. My aim is: if result is successful, just move along, if not, there are two ways to handle that panic.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Behold!

if predicate {
    do_things();
} else {
    // pass
}

Or even better

if predicate {
    do_things();
} // pass

Or as I’ve recently taken to calling it the implicit + pass system

if predicate {
    do_things();
}

In all seriousness there is no pass and no need for a pass in rust. As for why it exists in python, check out this answer

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading