-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Implement fixed-size-buffer constructors for CString #46795
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First impression: this seems a bit like a new string representation, next to str
and CStr
and OsStr
. Is it possible to expose this in a crate as something like a BoundedCStr
type with its own suite of constructors, and conversion to CString
? What would the API look like and would it be able to express the same use cases efficiently as the API here?
I don't think we have used the fn of_
naming convention in the standard library yet. Are the two of_
constructors doing something novel that does not match any existing naming convention?
(Have not reviewed the implementation yet.)
Yes, I'm starting to think this is the case
I will take a stab at designing this.
Typically the constructors do not copy the data - new/from/etc. variants take ownership of the underlying storage. The pattern for constructing an owned type typically looks like: |
Amazing work @Diggsey! I think those types will be more convenient to use than the constructors in this PR because they do a better job capturing how this representation is different from CString. What do you think? I guess the next thing to decide is whether this c-fixed-string representation is common enough that it makes sense pursuing these in the standard library, or whether we can direct people to a crate instead. |
Particularly given the amount of API surface that's needed to support this, I think it will have to exist as a crate until it's seen a good amount of usage. Let's close this PR and resolve the original issue with a link to this crate. |
Fixes #20475
I added three variants. Not sure about naming/whether we necessarily need all three.
For comparison, the existing constructors are:
r? @dtolnay