elevate-code-derive 0.1.0

将标记的函数自动以管理员权限运行。
Documentation
  • Coverage
  • 0%
    0 out of 2 items documented0 out of 1 items with examples
  • Size
  • Source code size: 6.34 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 280.55 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 5s Average build duration of successful builds.
  • all releases: 5s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • hamflx/elevated
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • hamflx

Elevate Code

通过一个宏,自动将函数包装为管理员权限执行,使用方法:

fn main() {
    println!("这里是以普通权限执行的代码");
    admin_right("Hello Rust".to_string());
}

#[elevate_code::elevate_code]
fn admin_right(msg: String) {
    println!("这里是以管理员权限执行的代码:{msg}");
}

注意,在 elevate_code 宏标记的函数中,不要使用全局变量,因为全局变量可能还没有初始化,而且,被标记的函数是使用新的进程启动的,全局变量的取值可能不对。

注意,被 elevate_code 宏标记的函数不可以重名。