-
Notifications
You must be signed in to change notification settings - Fork 24
Closed
Labels
ACP-acceptedAPI Change Proposal is accepted (seconded with no objections)API Change Proposal is accepted (seconded with no objections)T-libs-apiapi-change-proposalA proposal to add or alter unstable APIs in the standard librariesA proposal to add or alter unstable APIs in the standard libraries
Description
Proposal
Problem statement
The str and slice primitives both have is_empty() to check if a value is empty, but CStr currently doesn't. This is unfortunate because the CStr::to_bytes() function is documented as performing a length calculation in the future, which would make cstr_val.to_bytes().is_empty() into an O(N) operation.
Motivation, use-cases
There's many reasons a user might want to check if a C string is empty, for example when writing FFI bindings to code written in C that crashes if given an empty string.
Solution sketches
pub const fn is_empty(&self) -> bool {
(unsafe { self.inner.get_unchecked(0) }) == &0
}Links and related work
What happens now?
This issue is part of the libs-api team API change proposal process. Once this issue is filed the libs-api team will review open proposals in its weekly meeting. You should receive feedback within a week or two.
Metadata
Metadata
Assignees
Labels
ACP-acceptedAPI Change Proposal is accepted (seconded with no objections)API Change Proposal is accepted (seconded with no objections)T-libs-apiapi-change-proposalA proposal to add or alter unstable APIs in the standard librariesA proposal to add or alter unstable APIs in the standard libraries