Giter Site home page Giter Site logo

loop_unwrap's Introduction

View Documentaion at https://docs.rs/loop_unwrap/
Github Repository: https://github.com/Mrp1Dev/loop_unwrap

loop_unwrap

Provides utility macros for unwrapping during loops.

Works like .unwrap, if it's an Err or None, it calls continue on the loop. Prints an error message with println!() if provided. Loop Label can be provided in any order besides the Result/Option being the first argument. If loop label is proivded, the specified loop will be continued.

Examples

loop {
    let input = "Not a number";
    let parsed_input: i32 = unwrap_continue!(input.parse()); //parse returns Err for this input
    break; //<-- never reached, since `continue` is called.
}
loop {
    let input = "Not a number";
    let parsed_input: i32 = unwrap_continue!(input.parse(), "Please Enter a Number!");
    // "Please Enter a Number!" is printed in console with a `println!()`
    break;
}
loop {
    let some_value: i32 = unwrap_continue!(Some(32), "Please Enter a Number!");
    assert_eq!(some_value, 32_i32)
}
'main: loop {
    loop {
        let n = unwrap_continue!("t".parse::<i32>(), "Couldn't parse, retrying main loop", 'main);
        break 'main; //<-- this line will never be reached, and main will go into an infinite loop
    }
    break; //<-- this line won't be reached, since 'main will be continued infinitely
}

loop_unwrap's People

Contributors

mrp1dev avatar stargateur avatar rellfy avatar tonalidadehidrica avatar

Stargazers

 avatar Roman Hossain Shaon avatar  avatar

Watchers

 avatar

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.