Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/raw/cstr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,12 @@ impl<'a> From<&'a CStr> for &'a str {
}
}

impl Default for &CStr {
fn default() -> Self {
cstr!("")
}
}

#[cfg(feature = "serde")]
impl serde::Serialize for &CStr {
fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
Expand Down Expand Up @@ -233,7 +239,7 @@ pub use cstr;
///
/// Like `CStr`, this differs from [`std::ffi::CString`] in that it is required to be valid UTF-8,
/// and does not include the nul terminator in the buffer.
#[derive(Clone, Eq)]
#[derive(Clone, Eq, Default)]
#[repr(transparent)]
pub struct CString {
data: String,
Expand All @@ -258,6 +264,11 @@ impl TryFrom<&str> for CString {
}

impl CString {
/// Creates a new empty `CString`.
pub fn new() -> Self {
Self::default()
}

pub(crate) fn from_string_unchecked(data: String) -> Self {
Self { data }
}
Expand Down