macro_rules! polonius_break {
    ( $($e:expr $(,)?)? ) => { ... };
}
Expand description

break a non-dependent value out of a polonius_loop!.

  • When the value to break with is a dependent value / a value that is borrowing from the input, consider using polonius_break_dependent! instead.

Example

  • use {
        ::std::{
            collections::HashMap,
        },
        ::polonius_the_crab::{
            *,
        },
    };
    
    fn example (mut map: &'_ mut HashMap<u8, i32>)
      -> Option<&'_ mut i32>
    {
        let mut i = 0;
        let x = polonius_loop!(|map| -> Option<&'polonius mut i32> {
            if let Some(entry) = map.get_mut(&i) {
                polonius_return!(Some(entry));
            }
            i += 1;
            if i == 42 {
                polonius_break!(i);
            }
        });
        assert_eq!(x, i);
        // Access to the "captured" `map` is still possible if using `polonius_break!`
        // (and thus no `break: …` annotation on the "closure")
        map.clear();
        None
    }