diff options
| author | Gabriel Bjørnager Jensen <gabriel@achernar.io> | 2025-02-19 10:36:21 +0100 |
|---|---|---|
| committer | Gabriel Bjørnager Jensen <gabriel@achernar.io> | 2025-02-20 17:51:00 +0100 |
| commit | 817b0932fa66ee8fd6e695f9ec74804a6c360269 (patch) | |
| tree | 4f64cd91616c3497be1552f32472d50c9a954b1e /library/alloc/src | |
| parent | 5986ff05d8480da038dd161b3a6aa79ff364a851 (diff) | |
| download | rust-817b0932fa66ee8fd6e695f9ec74804a6c360269.tar.gz rust-817b0932fa66ee8fd6e695f9ec74804a6c360269.zip | |
Implement 'PartialEq<{&Self, CString, Cow<Self>}>' for 'CStr'; Implement 'PartialEq<{CStr, &CStr, Cow<CStr>}>' for 'CString'; Implement 'PartialEq<{CStr, &CStr, CString}>' for 'Cow<CStr>';
Diffstat (limited to 'library/alloc/src')
| -rw-r--r-- | library/alloc/src/ffi/c_str.rs | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/library/alloc/src/ffi/c_str.rs b/library/alloc/src/ffi/c_str.rs index fd93045a5ac..91cfb50c5e0 100644 --- a/library/alloc/src/ffi/c_str.rs +++ b/library/alloc/src/ffi/c_str.rs @@ -1095,6 +1095,46 @@ impl From<&CStr> for CString { } } +#[stable(feature = "c_string_eq_c_str", since = "CURRENT_RUSTC_VERSION")] +impl PartialEq<CStr> for CString { + #[inline] + fn eq(&self, other: &CStr) -> bool { + **self == *other + } + + #[inline] + fn ne(&self, other: &CStr) -> bool { + **self != *other + } +} + +#[stable(feature = "c_string_eq_c_str", since = "CURRENT_RUSTC_VERSION")] +impl PartialEq<&CStr> for CString { + #[inline] + fn eq(&self, other: &&CStr) -> bool { + **self == **other + } + + #[inline] + fn ne(&self, other: &&CStr) -> bool { + **self != **other + } +} + +#[cfg(not(no_global_oom_handling))] +#[stable(feature = "c_string_eq_c_str", since = "CURRENT_RUSTC_VERSION")] +impl PartialEq<Cow<'_, CStr>> for CString { + #[inline] + fn eq(&self, other: &Cow<'_, CStr>) -> bool { + **self == **other + } + + #[inline] + fn ne(&self, other: &Cow<'_, CStr>) -> bool { + **self != **other + } +} + #[stable(feature = "cstring_asref", since = "1.7.0")] impl ops::Index<ops::RangeFull> for CString { type Output = CStr; @@ -1178,6 +1218,75 @@ impl CStr { } } +#[stable(feature = "c_string_eq_c_str", since = "CURRENT_RUSTC_VERSION")] +impl PartialEq<CString> for CStr { + #[inline] + fn eq(&self, other: &CString) -> bool { + *self == **other + } + + #[inline] + fn ne(&self, other: &CString) -> bool { + *self != **other + } +} + +#[cfg(not(no_global_oom_handling))] +#[stable(feature = "c_string_eq_c_str", since = "CURRENT_RUSTC_VERSION")] +impl PartialEq<Cow<'_, Self>> for CStr { + #[inline] + fn eq(&self, other: &Cow<'_, Self>) -> bool { + *self == **other + } + + #[inline] + fn ne(&self, other: &Cow<'_, Self>) -> bool { + *self != **other + } +} + +#[cfg(not(no_global_oom_handling))] +#[stable(feature = "c_string_eq_c_str", since = "CURRENT_RUSTC_VERSION")] +impl PartialEq<CStr> for Cow<'_, CStr> { + #[inline] + fn eq(&self, other: &CStr) -> bool { + **self == *other + } + + #[inline] + fn ne(&self, other: &CStr) -> bool { + **self != *other + } +} + +#[cfg(not(no_global_oom_handling))] +#[stable(feature = "c_string_eq_c_str", since = "CURRENT_RUSTC_VERSION")] +impl PartialEq<&CStr> for Cow<'_, CStr> { + #[inline] + fn eq(&self, other: &&CStr) -> bool { + **self == **other + } + + #[inline] + fn ne(&self, other: &&CStr) -> bool { + **self != **other + } +} + +#[cfg(not(no_global_oom_handling))] +#[stable(feature = "c_string_eq_c_str", since = "CURRENT_RUSTC_VERSION")] +impl PartialEq<CString> for Cow<'_, CStr> { + #[inline] + fn eq(&self, other: &CString) -> bool { + **self == **other + } + + #[inline] + fn ne(&self, other: &CString) -> bool { + **self != **other + } +} + #[stable(feature = "rust1", since = "1.0.0")] impl core::error::Error for NulError { #[allow(deprecated)] |
