drop_code 1.0.1

A macro that allows you to implement code that will be automatically executed after the function code has finished, be it the end of the function or even a panic state.
Documentation
  • Coverage
  • 33.33%
    2 out of 6 items documented1 out of 1 items with examples
  • Size
  • Source code size: 51.36 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 637.62 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • Homepage
  • clucompany/drop_code
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • denisandroid

[drop_code]

(A macro that allows you to implement code that will be automatically executed after the function code has finished, be it the end of the function or even a panic state.)

CI

Usage

Add this to your Cargo.toml:

[dependencies]
drop_code = "1.0.1"

and this to your source code:

use drop_code::drop_code;

How does this work?

The drop_code macro generates a hidden structure and defines the code for the Drop trait, the user can pass any data to the structure to create more complex code. The Drop trait mechanism ensures that critical operations are executed when an object is destroyed, making it easier to reliably handle important code in Rust applications, but note that the order of code execution is determined by Rust's rules and conventions. Note that this code is executed even during a panic, but only if you have not disabled stack unwinding.

Example

use drop_code::drop_code;

#[allow(unreachable_code)]
fn main() {
	drop_code! {
		println!("Code that must be executed in any situation."); // 3
	}
	
	println!("your code"); // 1
	panic!("panic info"); // 2
}

License

This project has a single license (LICENSE-APACHE-2.0).

 (Denis Kotlyarov).

Apache License