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

Add InfoType::to_string method #3

Merged
merged 1 commit into from
Mar 26, 2021
Merged

Add InfoType::to_string method #3

merged 1 commit into from
Mar 26, 2021

Conversation

kenba
Copy link
Owner

@kenba kenba commented Mar 21, 2021

Currently, the InfoType::to_str method converts an OpenCL C string into a Result containing a Rust ffi::CString and a NulError.
The InfoType::to_str method now handles null characters in OpenCL C strings returned from some devices, see issue #2.

The new InfoType::to_string method converts an OpenCL C string into Rust String using the from_utf8_lossy method to convert invalid characters to std::char::REPLACEMENT_CHARACTER. It is intended to replace InfoType::to_str which is now marked with the deprecated attribute.

This change replaces all instances of InfoType::to_str in this library with InfoType::to_string.

The new InfoType::to_string method converts an OpenCL C string into Rust String using the `from_utf8_lossy` method to convert invalid characters to std::char::REPLACEMENT_CHARACTER. It is intended to replace `InfoType::to_str` which is now marked with the deprecated attribute.
@kenba kenba added the enhancement New feature or request label Mar 21, 2021
@kenba kenba self-assigned this Mar 21, 2021
@kenba kenba linked an issue Mar 21, 2021 that may be closed by this pull request
Copy link
Contributor

@vmx vmx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, I find that this makes the API nicer to use.

On a more general note (this would be another PR), I think the conversion methods should for InfoType should be implemented as https://doc.rust-lang.org/std/convert/trait.TryFrom.html implementations. I bring it up, as this PR already deprecates things and I want to prevent that new additions are deprecated soon after they got introduced (in case moving to TryFrom is something desirable).

@kenba
Copy link
Owner Author

kenba commented Mar 23, 2021

@vmx I don't understand what you want with the TryFrom trait.
Please can you explain or give an example in issue #4?

@kenba kenba merged commit 96eab46 into main Mar 26, 2021
@kenba kenba deleted the use_rust_strings branch March 26, 2021 08:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Change the API to use String instead of ffi::CString
2 participants