When calling a native function that takes a char* string or NULL for
the default behavior I treat the option like this
pub fn read_file(&self, path: Option<&str>) {
let c_path = match path {
Some(ref path) => path.to_c_str().with_ref(|x| x),
None => ptr::null()
};
unsafe {
native_read_file(self.ch, c_path) as int
};
}
Is this the best way to handle the situation?
`path.to_cstr().with_ref(|x| x)` seems a bit verbose. On the other
hand, `unwrap` says it forgets the ownership which I'm assuming means
that the buffer won't be freed.
-Noah
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev