-
Notifications
You must be signed in to change notification settings - Fork 13.9k
Open
Labels
A-FFIArea: Foreign function interface (FFI)Area: Foreign function interface (FFI)C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.This issue may need triage. Remove it if it has been sufficiently triaged.
Description
Hi,
Often times I see a fixed array of C chars returned via FFI boundary which cannot be easily converted into CStr
because:
CStr::from_ptr()
usesstrlen()
which can walk outside of boundaries of a fixed arrayCStr::from_bytes_until_nul(&[u8])
takesu8
slice.
Each time I stumble upon [c_char; N]
it's always a struggle.
As such I think CStr
should have an initializer from &[c_char]
slice. This would work identical to CStr::from_ptr()
except it wouldn't need to use strlen
. It could flip the slice into &[u8]
and then pass it into from_bytes_until_nul
.
thughes
Metadata
Metadata
Assignees
Labels
A-FFIArea: Foreign function interface (FFI)Area: Foreign function interface (FFI)C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.This issue may need triage. Remove it if it has been sufficiently triaged.