dont_panic

Crates.iodont_panic
lib.rsdont_panic
version0.1.0
sourcesrc
created_at2017-07-06 20:27:39.31031
updated_at2017-07-06 20:27:39.31031
descriptionpanic!()-like macro that causes linking error instead of panicking. May be used to statically ensure some code won't panic.
homepagehttps://github.com/Kixunil/dont_panic
repositoryhttps://github.com/Kixunil/dont_panic
max_upload_size
id22235
size4,003
Martin Habovštiak (Kixunil)

documentation

README

Don't panic!()

Ensure that code can't panic at compile time.

Example

This code will compile and (not) run just fine:

let should_panic = false;
if should_panic {
    dont_panic!("This will never execute.");
}

However, this code will cause linking error:

let should_panic = true;
if should_panic {
    dont_panic!("This will never execute.");
}

Caveats

  • This works only when appropriate opt_level is specified - it may require release build.
  • The error message is weird link error. You don't get line number, etc.
  • There may be situations in which you know that the code is unreachable but compiler can't prove it.
Commit count: 13

cargo fmt