Repository navigation
Conversation
teor2345
left a comment
There was a problem hiding this comment.
Hi, thank you for this PR!
Please submit steps 2 & 3 immediately, without waiting for reviews. Outreachy applications are due on Monday 9 November, and I want you to be able to get one or two reviews of everything in your PR.
Please remember to submit an Outreachy application! You can include any Rust work during the application period.
I added a merge commit, feel free to keep it or force-push over it.
| //! | ||
| //! Callers can only build a view from static data, such as string-literal constants, constant | ||
| //! arrays, or a leaked `Box`. A view of a local array is a compile error. Supporting borrowed | ||
| //! data needs generics (and lifetime) support in `overload!`. |
There was a problem hiding this comment.
Please move all this documentation next to the types or functions it documents. That way, when we fix these issues, we will see the documentation and update it.
| /// | ||
| /// `std::basic_string_view<CharT>` is a template, so this wrapper is hardcoded to `char32_t`. | ||
| #[cfg_attr(not(test), expect(dead_code, reason = "Only used in tests"))] | ||
| pub struct StdU32StringView(*mut c_void); |
There was a problem hiding this comment.
Rust requires a marker type to show what this type contains behind the pointer.
| pub struct StdU32StringView(*mut c_void); | |
| pub struct StdU32StringView(*mut c_void, PhantomData<CharT>); |
There was a problem hiding this comment.
Thanks for this suggestion, I will apply it.
| #[cfg_attr(not(test), expect(dead_code, reason = "Only used in tests"))] | ||
| pub struct StdU32StringView(*mut c_void); | ||
|
|
||
| /// The C++ `char32_t` type is used as `u32` in Rust since it has the same size and alignment. |
There was a problem hiding this comment.
Unfortunately, this is not guaranteed, even if most C++ platforms do it that way:
https://en.cppreference.com/c/string/multibyte/char32_t
This is a portability limitation, which could result in a compiler failure on weird platforms (the cpp! macro checks size and alignment match). Please update the docs here, document this limitation, and link to the reference.
It is true Rust does not have a corresponding type in its standard library, but it could in future.
There was a problem hiding this comment.
Thanks fpr pointing this out.
I'll update the documentation to explain that u32 is the Rust-side representation, but compatibility with C++ char32_t depends on the target platform.
I will also document the limitation and add the reference link.
| impl<'a> NullTerminated<'a> { | ||
| /// Returns `None` if `s` has no zero terminator, because C++ would read past the end. | ||
| pub fn new(s: &'a [CharT]) -> Option<NullTerminated<'a>> { | ||
| s.contains(&0).then_some(NullTerminated(s)) |
There was a problem hiding this comment.
What happens if the null terminator is not at the end of the slice?
There was a problem hiding this comment.
Characters after the null terminator will be ignored even if they are not at the end of the slice since the C++ constructor stops reading at the first null terminator.
There was a problem hiding this comment.
This might be worth documenting?
| StdU32StringView(view) | ||
| } | ||
|
|
||
| fn copy_from(other: &StdU32StringView) -> StdU32StringView { |
There was a problem hiding this comment.
This constructor is only sound because all the other constructors take static data. Otherwise, it could extend the lifetime of the new string view beyond the lifetime of its contents.
There was a problem hiding this comment.
I agree.
The copy constructor only copies the std::u32string_view and does not extend the lifetime of the underlying character storage.
The current implementation relies on all constructors restricting the underlying character data to 'static, which makes this safe. I'll document this invariant alongside the copy constructor.
| //! Wrapped overloaded names: constructors, `compare`, `find`, `starts_with`. | ||
| //! | ||
| //! The `basic_string_view(nullptr_t) = delete` constructor (C++23) is not wrapped. | ||
| //! It exists only to reject `nullptr` at compile time, and Rust raw pointers |
There was a problem hiding this comment.
| //! It exists only to reject `nullptr` at compile time, and Rust raw pointers | |
| //! It exists only to reject `nullptr` at compile time, and Rust references |
Thank you @teor2345 for the reminder! |
|
Just reminding you that the Outreachy final application deadline is this Monday 9 November. You can include any Rust PR or ticket work you've done, it doesn't have to be merged (or reviewed) yet. Please submit a final application on the Outreachy website before Monday. The exact deadline is 4pm UTC, but it is better to submit early. You can edit your submitted application up until the deadline (and you can keep working on PRs after the deadline). |
Added a wrapper for std::U32string_view with 4 overloads including
constructor, and methods:compare,findandstartwithImplements #43
Write Rust wrappers for that U32string_view, for 3-5 different overloaded method names:
Limitationsdoc sectionErgonomicsdoc sectionAdd a separate example with some failing overloads
Incompatibilitiesdoc sectionWorkaroundsdoc sectionInexpressible Overloadsdoc sectionUpdate the overload macro compatibility table Markdown doc