On 12-06-18 11:12 AM, Brian Anderson wrote:

It is ok, as long as you make sure that you hold the reference to my_str
for at least as long as my_cstr (as_c_str is simply passing a pointer
into the Rust string).

This is only true by accident now and is going to stop being true when we move to slices. In particular, a slice that points into a non-terminal substring will be copied into a temp buffer and null terminated before passing back to such a closure for use in C. So then it's _really_ garbage memory after the closure returns.

Generally: copy the string out if you want it to survive after the closure.

-Graydon



_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to