[rust-dev] strings, slices and nulls

Brian Anderson banderson at mozilla.com
Wed Apr 18 13:58:56 PDT 2012


On 04/18/2012 01:37 PM, Graydon Hoare wrote:
> On 12-04-18 12:43 PM, Niko Matsakis wrote:
>
>> I can see the practicality of null-terminating, but I would really like
>> to preserve the flexibility to reverse that decision in the future.
>> Forcing people to go through str::as_bytes() to observe the null
>> terminating seems like a win—except that I'd probably call it as_cstr()
>> or something like that, to emphasize it's null-terminated-ness.
>
> Right, but .. you can still observe it by allocating a str/5 in a record
> and noticing that it takes 6 bytes (i.e. with sizeof). Tolerable?

I think this is acceptable, Who's to say what that other byte is really 
doing there?


More information about the Rust-dev mailing list