-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Implement CStr
as a pointer rather than a slice
#59905
Comments
I'm not sure if this needs an RFC. If so I can make it. |
Potential complications: |
The current definition makes |
Perhaps we do something like
But that would require |
|
This seems to be prior art: https://github.com/kennytm/thin_cstr |
Thanks @LifeIsStrange . I couldn't find an open issue for this so I'll keep it open |
here are the blockers (custom DST support) kennytm/thin_cstr#1 |
Is it worth adding a link in the documentation to this issue? So that future readers know where to look. |
This seems wrong. Proper |
@RalfJung I already noted it above. It's a good point though and an interesting design decision |
Does #81513 contain what is needed to make this work? |
Before this is resolved, is there a way to create a null pointer of |
@bobogei81123 CStr is a bit of a weird type - &CStr is actually two pointers wide, it stores both a pointer and a length (same for &str or &[T]). What do you need the pointer for? If you need to interface with a C method that takes a string, use a null |
Oh got it. I thought |
Littered throughout the
CStr
documentation are notes and hints that it should be eventually converted to using a pointer underneath the hood instead of a slice. This change will makeCStr::from_ptr
O(1) instead of O(n). Other constructors may still be O(n) because they have to check to ensure there is only one null terminator. If someone wants to try implementing this, it seems like a pretty simple change.Current struct definition:
Proposed:
The text was updated successfully, but these errors were encountered: