#trust #macro #safe #unsafe #programmers #alloc #wrap

trust_me

只需将不安全关键字替换为 safe! 宏。永远信任程序员。

2个版本

0.1.1 2023年12月7日
0.1.0 2023年12月7日

#412 in 内存管理

自定义许可证

3KB

信任我,这是 safe!

一个宏,将不安全关键字包装进 safe! 宏。 永远信任程序员。

use std::alloc::{alloc, dealloc, Layout};

use trust_me::safe;

fn main() {
    // TRUST ME! THIS IS SAFE!!!
    safe! {
        let layout = Layout::new::<u32>();
        let ptr = alloc(layout);
        *(ptr as *mut u32) = 42;
        dealloc(ptr, layout)
    }
}

无运行时依赖