From 57c46f4dd86192906cb13a6a9d1a2df00767ef41 Mon Sep 17 00:00:00 2001 From: Josh Megnauth Date: Mon, 21 Jul 2025 23:47:50 -0400 Subject: [PATCH] Backport count_bytes and is_empty for CStr --- src/c_str.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/c_str.rs b/src/c_str.rs index 9aa0639776..0f7562d9f0 100644 --- a/src/c_str.rs +++ b/src/c_str.rs @@ -77,6 +77,12 @@ impl<'a> CStr<'a> { pub fn borrow(string: &'a CString) -> Self { unsafe { Self::from_ptr(string.as_ptr()) } } + pub fn count_bytes(&self) -> usize { + self.to_bytes().len() + } + pub fn is_empty(&self) -> bool { + self.count_bytes() == 0 + } } unsafe impl Send for CStr<'_> {}