Crate box_raw_ptr
source ·Expand description
§box_raw_ptr
box_raw_ptr is a Rust library providing safe wrappers for working with raw pointers,
specifically *const T and *mut T. These wrappers ensure memory safety by encapsulating
the raw pointers in safe abstractions and providing safe methods for working with them.
§Features
- ConstRawPtr: A wrapper for
*const Tproviding methods for safely working with constant raw pointers. - MutRawPtr: A wrapper for
*mut Tproviding methods for safely working with mutable raw pointers.
§Example
use box_raw_ptr::const_raw_ptr::ConstRawPtr;
fn main() {
let ptr = Box::new(42);
let raw_ptr = ConstRawPtr::new_const_ptr(&*ptr);
// Print the memory address of the raw pointer
raw_ptr.print_const_ptr(true);
// Print the value pointed to by the raw pointer
raw_ptr.print_const_ptr(false);
}§Usage
Add this to your Cargo.toml:
[dependencies]
box_raw_ptr = "0.1.8"
§License
This project is licensed under the MIT license. See the LICENSE file for details.
§Contributions
Contributions are welcome! Please feel free to submit a pull request or open an issue on the GitHub repository.
extern crate box_raw_ptr;
use box_raw_ptr::const_raw_ptr::ConstRawPtr;
fn main() {
let ptr = Box::new(42);
let raw_ptr = ConstRawPtr::new_const_ptr(&*ptr);
// Print the memory address of the raw pointer
raw_ptr.print_const_ptr(true);
// Print the value pointed to by the raw pointer
raw_ptr.print_const_ptr(false);
}