-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Closed
Description
Add a CStr::from_bytes function with a following API (or something along the lines):
enum CStrFromBytesError {
InteriorNullBytes,
NoEndingNullByte,
};
impl CStr {
fn from_bytes(bytes: &[u8]) -> Result<&CStr, CStrFromBytesError>;
}
Which converts a bytestring with a trailing null byte to a C string slice. If the slice does not have a trailing null byte or has a null byte in any position that’s not the last byte appropriate error is returned.
This is useful in APIs where a &CStr
is expected and you can/want to pass in a static string (e.g. b"helloworld\0"
).
Metadata
Metadata
Assignees
Labels
No labels