├── .editorconfig ├── .gitignore ├── Cargo.toml ├── LICENSE ├── README.md ├── src └── lib.rs └── tests └── test.rs /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | charset = utf-8 5 | end_of_line = lf 6 | insert_final_newline = true 7 | indent_size = 4 8 | indent_style = space 9 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | /Cargo.lock 3 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "trust_me" 3 | version = "0.1.1" 4 | edition = "2021" 5 | license-file = "LICENSE" 6 | description = "Just replace unsafe keyword to `safe!` macro. Always trust programmers." 7 | homepage = "https://github.com/Guyutongxue/trust_me_crab" 8 | documentation = "https://docs.rs/trust_me" 9 | repository = "https://github.com/Guyutongxue/trust_me_crab" 10 | readme = "README.md" 11 | 12 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 13 | 14 | [lib] 15 | crate-type = ["lib"] 16 | 17 | [dependencies] 18 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE 2 | Version 2, December 2004 3 | 4 | Copyright (C) 2004 Sam Hocevar 5 | 6 | Everyone is permitted to copy and distribute verbatim or modified 7 | copies of this license document, and changing it is allowed as long 8 | as the name is changed. 9 | 10 | DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE 11 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 12 | 13 | 0. You just DO WHAT THE FUCK YOU WANT TO. 14 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Trust me, this is `safe!` 2 | 3 | A macro wrap `unsafe` keyword into `safe!` macro. **Always trust programmers.** 4 | 5 | ```rust 6 | use std::alloc::{alloc, dealloc, Layout}; 7 | 8 | use trust_me::safe; 9 | 10 | fn main() { 11 | // TRUST ME! THIS IS SAFE!!! 12 | safe! { 13 | let layout = Layout::new::(); 14 | let ptr = alloc(layout); 15 | *(ptr as *mut u32) = 42; 16 | dealloc(ptr, layout) 17 | } 18 | } 19 | ``` 20 | -------------------------------------------------------------------------------- /src/lib.rs: -------------------------------------------------------------------------------- 1 | /// Just wrap unsafe keyword. 2 | /// 3 | /// Trust me; everything will be SAFE. 4 | #[macro_export] 5 | macro_rules! safe { 6 | ($($x:tt)*) => { 7 | unsafe { 8 | $($x)* 9 | } 10 | }; 11 | } 12 | -------------------------------------------------------------------------------- /tests/test.rs: -------------------------------------------------------------------------------- 1 | use trust_me::safe; 2 | 3 | #[test] 4 | fn test_safe() { 5 | use std::alloc::{alloc, dealloc, Layout}; 6 | let layout = Layout::new::(); 7 | 8 | // TRUST ME! THIS IS SAFE!!! 9 | safe! { 10 | let ptr = alloc(layout); 11 | *(ptr as *mut u32) = 42; 12 | assert_eq!(42, *(ptr as *mut u32)); 13 | dealloc(ptr, layout) 14 | } 15 | } 16 | --------------------------------------------------------------------------------