Function leetcode_test_utils::tree::shortcuts::to_ptr_mut[][src]

pub fn to_ptr_mut(root: Option<&Rc<RefCell<TreeNode>>>) -> *mut TreeNode
Expand description

Convert the rust style mutable pointer(specified in leetcode) into C/C++ style mutable pointer.

Returns the mutable pointer handled by root if is Some, or std::ptr::null_mut() is returned. Rust is so famous for its safety, in which the most safe way to operate on a pointer is to borrow a RefCell at runtime. But sometimes you really want to let the program perform the best(yeah, you do not want to be penalized anyway) as if you run the corresponding raw C/C++ code. This function provides the railway for you. Be CAREFUL!

Examples

use leetcode_test_utils::tree::shortcuts::to_ptr_mut;
use leetcode_test_utils::tree::T;
use leetcode_test_utils::btree;

let root = btree!(42, null, 50);
let ptr_root_right = to_ptr_mut(root.as_ref());
unsafe{
    (*ptr_root_right).val = 45;
}
let tree1 = T(root);
let tree2 = T(btree!(45, null, 50));
assert_eq!(tree1, tree2);