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

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

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

Returns the immutable pointer handled by root if it is Some, or std::ptr::null() 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 highway for you. Be careful!

Examples

use leetcode_test_utils::tree::shortcuts::{new_node, to_ptr};
use leetcode_test_utils::btree;
let root = btree!(42, 10);  // ok, `root->left->val` is 10
unsafe{
    assert_eq!((*to_ptr((*to_ptr(root.as_ref())).left.as_ref())).val, 10);
}
assert_eq!(to_ptr(None), std::ptr::null());