drop_code

Crates.iodrop_code
lib.rsdrop_code
version1.0.0
sourcesrc
created_at2024-04-07 22:54:01.808974
updated_at2024-04-07 22:54:01.808974
descriptionMacro for ensuring critical code execution on function return or panics in Rust, making it easy to include essential code for reliable operation.
homepagehttps://github.com/clucompany/drop_code.git
repositoryhttps://github.com/clucompany/drop_code.git
max_upload_size
id1199593
size51,453
Denis Kotlyarov (denisandroid)

documentation

README

Usage:

Add this to your Cargo.toml:

[dependencies]
drop_code  = "1.0.0"

and this to your source code:

use drop_code::drop_code;

Technical concept:

The drop_code macro generates the drop function code for the Drop trait in Rust, creating a hidden structure that encapsulates user-supplied arguments from the macro and ensuring their transfer. This mechanism guarantees the execution of critical operations when the object is destroyed, facilitating reliable handling of essential code within Rust applications, with the order of code execution dictated by Rust's rules and conventions.

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
}
See all

License:

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

uproject  Copyright (c) 2022-2024 #UlinProject

 (Denis Kotlyarov).


Apache License:

apache2  Licensed under the Apache License, Version 2.0.



Commit count: 20

cargo fmt