| name | maverick-rust-unsafe |
| description | Rust unsafe code, FFI, and safety invariants Use when this capability is needed. |
| metadata | {"author":"get2knowio"} |
Rust Unsafe Skill
When to Use Unsafe
- FFI with C libraries
- Raw pointers for performance
- Type transmutation (rare, dangerous)
- Unsafe trait implementations
Safety Documentation
unsafe fn get_first_unchecked(slice: &[i32]) -> i32 {
debug_assert!(!slice.is_empty());
*slice.get_unchecked(0)
}
Avoid Unsafe When Possible
unsafe fn get_first(slice: &[i32]) -> i32 {
*slice.get_unchecked(0)
}
fn get_first(slice: &[i32]) -> Option<&i32> {
slice.first()
}
Review Severity
- CRITICAL: Unsafe without justification, potential undefined behavior
- MAJOR: Missing safety documentation, unsafe could be safe
- MINOR: Debug assertions missing in unsafe code
Converted and distributed by TomeVault — claim your Tome and manage your conversions.