|
|
Log in / Subscribe / Register

Rust in the 6.2 kernel

Rust in the 6.2 kernel

Posted Nov 18, 2022 3:18 UTC (Fri) by droundy (guest, #4559)
In reply to: Rust in the 6.2 kernel by tialaramex
Parent article: Rust in the 6.2 kernel

Actually &CStr differs from &str in that it is *not* a slice and doesn't hold a length asking with an address. So while I do prefer the standard &str, &CStr does have the advantage of taking up half as much space.


to post comments

Rust in the 6.2 kernel

Posted Nov 18, 2022 3:59 UTC (Fri) by ABCD (subscriber, #53650) [Link] (1 responses)

CStr (both kernel::str::CStr and core::ffi::CStr) are implemented as dynamically-sized types (specifically, a newtype wrapper around [u8]), so a &CStr is a fat pointer containing both the pointer to the data and the length of that data, just like a &str or &[u8].

Rust in the 6.2 kernel

Posted Nov 18, 2022 14:21 UTC (Fri) by xav (guest, #18536) [Link]

It is yes, but AFAIK it's an oversight and could be replaced soon with a thin pointer - this is alluded to here for example: https://github.com/m-ou-se/rfcs/blob/c-str-literal/text/3...


Copyright © 2026, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds