Skip to content
Closed
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 @@ -92,6 +92,12 @@ impl CStr {
}
}

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

impl PartialEq for CStr {
fn eq(&self, other: &CStr) -> bool {
self.as_str() == other.as_str()
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