CStr from fixed c_char array
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
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])takesu8slice.
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the existing CStr::from_ptr and CStr::from_bytes_until_nul entry points described in the issue, along with how [c_char] slices cross the FFI boundary. Define the bounded conversion's API and safety behavior, then add coverage showing fixed c_char arrays are handled without scanning beyond the slice.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- api
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100