On 21.08.24 14:08, Alice Ryhl wrote:
On Mon, Aug 19, 2024 at 5:39 PM Michal Rostecki vadorovsky@gmail.com wrote:
From: Michal Rostecki vadorovsky@gmail.com
`CStr` became a part of `core` library in Rust 1.75. This change replaces the custom `CStr` implementation with the one from `core`.
`core::CStr` behaves generally the same as the removed implementation, with the following differences:
- It does not implement `Display`.
- It does not provide `from_bytes_with_nul_unchecked_mut` method.
- It has `as_ptr()` method instead of `as_char_ptr()`, which also returns `*const c_char`.
The first two differences are handled by providing the `CStrExt` trait, with `display()` and `from_bytes_with_nul_unchecked_mut()` methods. `display()` returns a `CStrDisplay` wrapper, with a custom `Display` implementation.
`DerefMut` implementation for `CString` is removed here, as it's not being used anywhere.
Signed-off-by: Michal Rostecki vadorovsky@gmail.com
A few comments:
- I would probably add CStrExt to the kernel prelude.
- I would probably remove `from_bytes_with_nul_unchecked_mut` and keep
`DerefMut for CString` instead of the other way around.
- Perhaps we should remove the `c_str!` macro and use c"" instead?
Read [1], it is needed, because there is no `c_stringify!` macro.
[1]: https://lore.kernel.org/rust-for-linux/52676577-372c-4a7f-aace-4cf100f93bfb@...
--- Cheers, Benno