Skip to content

Commit 85688d8

Browse files
committed
Implement Deref<Target=ByteStr> for CStr
This produces a deref chain of `CStr` -> `BStr` -> `[u8]` which is present in the Rust-for-Linux analogues of these types. Link: #134915 Link: Rust-for-Linux/linux#1075 Link: https://lore.kernel.org/all/20250221142816.0c015e9f@eugeo/ Link: Rust-for-Linux/linux#1146
1 parent f7b4354 commit 85688d8

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

library/core/src/ffi/c_str.rs

+8
Original file line numberDiff line numberDiff line change
@@ -710,6 +710,14 @@ impl AsRef<CStr> for CStr {
710710
}
711711
}
712712

713+
impl ops::Deref for CStr {
714+
type Target = crate::bstr::ByteStr;
715+
716+
fn deref(&self) -> &Self::Target {
717+
crate::bstr::ByteStr::from_bytes(self.to_bytes())
718+
}
719+
}
720+
713721
/// Calculate the length of a nul-terminated string. Defers to C's `strlen` when possible.
714722
///
715723
/// # Safety

0 commit comments

Comments
 (0)