[rust-dev] strings, slices and nulls

Jesse Ruderman jruderman at gmail.com
Thu Apr 19 07:25:24 PDT 2012


My preference is to remove null termination:

* I'm guessing most strings aren't passed to C. (What are the most
common C string calls in rustc?)

* C functions that scan for null are inefficient, so they're even more
likely to be replaced with Rust equivalents than other C functions.

* Null termination is not sufficient for interop with C. You also have
to ensure the strings don't contain null characters. (This is a common
source of bugs in Firefox, since JavaScript strings and strings from
the network can contain null characters.) And if null characters are
present, what do you do?

* Each C function has its own expectations about character encoding
and allowed characters, so calls to C involve extra state-tracking or
checks anyway.


More information about the Rust-dev mailing list