Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TryFromBytes/IntoBytes for CStr #2282

Open
kupiakos opened this issue Feb 1, 2025 · 0 comments
Open

TryFromBytes/IntoBytes for CStr #2282

kupiakos opened this issue Feb 1, 2025 · 0 comments
Labels
customer-request Documents customer requests.

Comments

@kupiakos
Copy link
Contributor

kupiakos commented Feb 1, 2025

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 <CStr as TryFromBytes>::try_ref_from_bytes and <CStr as IntoBytes>::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?
@kupiakos kupiakos added the customer-request Documents customer requests. label Feb 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
customer-request Documents customer requests.
Projects
None yet
Development

No branches or pull requests

1 participant