Skip to content

Add an explicit conversion operator from rust::Str to std::string_view. #1486

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

Conversation

anforowicz
Copy link
Contributor

PTAL?

I am aware of #80 (adding a way to construct rust::Str from std::string_view, using a custom C++17-detection mechanism) and #410 (adding a way to construct rust::String from std::string_view, also using a custom C++17 detection mechanism). But maybe we can still proceed with this PR given that:

  • This PR is relatively simple - just adds one member (a conversion operator) to rust::Str. I think that adding such an explicit operator has close to zero risk of breaking existing users (unlike the other PRs where new constructor overloads may risk ambiguity or other resolution problems)
  • Since the other PRs were raised, we were able to proceed with other C++-version-dependent APIs:

FWIW I've also noticed 5ae3a93 where #if __cplusplus >= 202002L was replaced with #ifdef __cpp_char8_t. IIUC this is using https://en.cppreference.com/w/cpp/utility/feature_test which are available in C++20 and later. So I think we can't do that in this PR.

Copy link
Owner

@dtolnay dtolnay left a comment

Choose a reason for hiding this comment

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

Thanks!

@dtolnay dtolnay merged commit 4661af8 into dtolnay:master Mar 26, 2025
22 checks passed
@anforowicz anforowicz deleted the rust-str-operator-for-converting-to-string-view branch April 8, 2025 16:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants