google / google/zerocopy

`TryFromBytes`/`IntoBytes` for `CStr`

Open
#2,282 0 comments 2 reactions 0 assignees View on GitHub
customer-request
Dominant language
Rust
Stars
2.6k
Forks
179
Avg merge
1d 19h
Merged PRs (30d)
29

Description

`core::ffi::CStr` doesn't implement `TryFromBytes` or `IntoBytes`, but it meets the requirements for both.

Currently `core::ffi::CStr` is a wrapper around `[u8]`, but theoretically it'll change so `&CStr` is a thin pointer.

Before this lands, we should seriously consider:

- Is `::try_ref_from_bytes` and `::as_bytes` eventually having dynamic performance unacceptable?
- Is it risky to use `mem::size_of_val` for a `CStr`? `mem::size_of_val(&cstr)` currently works today, so it'd be very surprising if that breaks for `CStr` even when extern types land. Would upstream really break its current behavior on stable?
- zerocopy would always include the `nul` byte in `as_bytes` - could that be confusing?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.