diff options
| author | Yuri Astrakhan <YuriAstrakhan@gmail.com> | 2024-12-10 15:45:23 -0500 |
|---|---|---|
| committer | Yuri Astrakhan <YuriAstrakhan@gmail.com> | 2025-01-11 02:47:55 -0500 |
| commit | 2f5a3d4b06a0a9e8749c2e361758ec517df0c96a (patch) | |
| tree | fcdcc4aa09220a582e148a6369ccc1faec850a11 /compiler/rustc_codegen_gcc | |
| parent | a2d7c8144f3f237612b37420fe2b6b08408d5b1d (diff) | |
| download | rust-2f5a3d4b06a0a9e8749c2e361758ec517df0c96a.tar.gz rust-2f5a3d4b06a0a9e8749c2e361758ec517df0c96a.zip | |
Convert `struct FromBytesWithNulError` into enum
One of `CStr` constructors, `CStr::from_bytes_with_nul(bytes: &[u8])` handles 3 cases: 1. `bytes` has one NULL as the last value - creates CStr 2. `bytes` has no NULL - error 3. `bytes` has a NULL in some other position - error The 3rd case is error that may require lossy conversion, but the 2nd case can easily be handled by the user code. Unfortunately, this function returns an opaque `FromBytesWithNulError` error in both 2nd and 3rd case, so the user cannot detect just the 2nd case - having to re-implement the entire function and bring in the `memchr` dependency. In [this code](https://github.com/gquintard/varnish-rs/blob/f86d7a87683b08d2e634d63e77d9dc1d24ed4a13/varnish-sys/src/vcl/ws.rs#L158), my FFI code needs to copy user's `&[u8]` into a C-allocated memory blob in a NUL-terminated `CStr` format. My code must first validate if `&[u8]` has a trailing NUL (case 1), no NUL (adds one on the fly - case 2), or NUL in the middle (3rd case - error). I had to re-implement `from_bytes_with_nul` and add `memchr`dependency just to handle the 2nd case. This PR renames the former `kind` enum from `FromBytesWithNulErrorKind` to `FromBytesWithNulError`, and removes the original struct.
Diffstat (limited to 'compiler/rustc_codegen_gcc')
0 files changed, 0 insertions, 0 deletions
