Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rust: add to_str and as_str_unchecked to CStr #533

Merged
merged 3 commits into from
Oct 28, 2021

Conversation

mdaverde
Copy link

@mdaverde mdaverde commented Oct 26, 2021

Following the std::ffi::CStr pattern of to_str, this adds
methods to convert between CStr and &str both safely and unsafely

Closes #532

Signed-off-by: Milan Landaverde [email protected]

rust/kernel/str.rs Outdated Show resolved Hide resolved
rust/kernel/str.rs Outdated Show resolved Hide resolved
rust/kernel/str.rs Outdated Show resolved Hide resolved
rust/kernel/str.rs Outdated Show resolved Hide resolved
rust/kernel/str.rs Outdated Show resolved Hide resolved
@ojeda
Copy link
Member

ojeda commented Oct 26, 2021

A couple more nits:

  • Please add intra-doc links wherever possible, e.g. in mentions to CStr and &str.
  • In the commit message: the functions are about converting CStr to &str, not "between" (this does not matter much today, since the commit messages do not go into the kernel, but eventually they will! :)

@gurugio
Copy link

gurugio commented Oct 26, 2021

Hi,

I would like to run the unit-tests in your patch.
Could you please inform me how to run the unit-tests in the patch?
I knew how to run the unit-test in normal user-mode application with Rust
but I've not seen the unit-test in kernel code.

I have a VM running the kernel with Rust and loading the modules implemented with Rust.
I ran the user-mode application unit-test with VisualStudio and Cargo in the VM.
I guess it would be very different to run the unittest of kernel code.

mdaverde and others added 3 commits October 28, 2021 13:09
Following the `std::ffi::CStr` pattern of `to_str`, this adds
methods to convert CStr to &str both safely and unsafely

Signed-off-by: Milan Landaverde <[email protected]>
Co-authored-by: Miguel Ojeda <[email protected]>
Signed-off-by: Milan Landaverde <[email protected]>
For to_str & as_str_unchecked

Signed-off-by: Milan Landaverde <[email protected]>
@mdaverde
Copy link
Author

From @ojeda

A couple more nits:

* Please add intra-doc links wherever possible, e.g. in mentions to `CStr` and `&str`.

Went ahead and added these

* In the commit message: the functions are about converting `CStr` to `&str`, not "between" (this does not matter much today, since the commit messages do not go into the kernel, but eventually they will! :)

Updated this commit message as well

@mdaverde
Copy link
Author

From @gurugio

I would like to run the unit-tests in your patch. Could you please inform me how to run the unit-tests in the patch? I knew how to run the unit-test in normal user-mode application with Rust but I've not seen the unit-test in kernel code.

Hello! I've been running the tests with make LLVM=1 rusttest

@ojeda ojeda merged commit b9ed1ad into Rust-for-Linux:rust Oct 28, 2021
@ojeda
Copy link
Member

ojeda commented Oct 28, 2021

Looks good to me! Thanks for contributing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Add a method to CStr to get &str out of it
3 participants