rust: str: add conversion from `CStr` to `CString`
authorAlice Ryhl <aliceryhl@google.com>
Wed, 3 May 2023 14:10:16 +0000 (14:10 +0000)
committerMiguel Ojeda <ojeda@kernel.org>
Wed, 31 May 2023 16:53:10 +0000 (18:53 +0200)
commit66bd7533ef19bf8a3515ce702013aba368f58df3
tree01750da9020ab71d9df5eedf7e4f82a3f794a2ed
parent4a59081c09cbfe17505baf3db50ebb9b97290bae
rust: str: add conversion from `CStr` to `CString`

These methods can be used to copy the data in a temporary c string into
a separate allocation, so that it can be accessed later even if the
original is deallocated.

The API in this change mirrors the standard library API for the `&str`
and `String` types. The `ToOwned` trait is not implemented because it
assumes that allocations are infallible.

Reviewed-by: Benno Lossin <benno.lossin@proton.me>
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
Reviewed-by: Martin Rodriguez Reboredo <yakoyoku@gmail.com>
Reviewed-by: Andreas Hindborg <a.hindborg@samsung.com>
Link: https://lore.kernel.org/r/20230503141016.683634-1-aliceryhl@google.com
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
rust/kernel/str.rs