pub trait CStrExt: Sealed {
// Required methods
unsafe fn from_char_ptr<'a>(ptr: *const c_char) -> &'a Self;
unsafe fn from_bytes_with_nul_unchecked_mut(bytes: &mut [u8]) -> &mut Self;
fn as_char_ptr(&self) -> *const c_char;
fn to_cstring(&self) -> Result<CString, AllocError>;
fn make_ascii_lowercase(&mut self);
fn make_ascii_uppercase(&mut self);
fn to_ascii_lowercase(&self) -> Result<CString, AllocError>;
fn to_ascii_uppercase(&self) -> Result<CString, AllocError>;
}
Expand description
Extensions to CStr
.
Required Methods§
Sourceunsafe fn from_char_ptr<'a>(ptr: *const c_char) -> &'a Self
unsafe fn from_char_ptr<'a>(ptr: *const c_char) -> &'a Self
Wraps a raw C string pointer.
§Safety
ptr
must be a valid pointer to a NUL
-terminated C string, and it must
last at least 'a
. When CStr
is alive, the memory pointed by ptr
must not be mutated.
Sourceunsafe fn from_bytes_with_nul_unchecked_mut(bytes: &mut [u8]) -> &mut Self
unsafe fn from_bytes_with_nul_unchecked_mut(bytes: &mut [u8]) -> &mut Self
Sourcefn as_char_ptr(&self) -> *const c_char
fn as_char_ptr(&self) -> *const c_char
Returns a C pointer to the string.
Sourcefn to_cstring(&self) -> Result<CString, AllocError>
fn to_cstring(&self) -> Result<CString, AllocError>
Sourcefn make_ascii_lowercase(&mut self)
fn make_ascii_lowercase(&mut self)
Converts this CStr
to its ASCII lower case equivalent in-place.
ASCII letters ‘A’ to ‘Z’ are mapped to ‘a’ to ‘z’, but non-ASCII letters are unchanged.
To return a new lowercased value without modifying the existing one, use
to_ascii_lowercase()
.
Sourcefn make_ascii_uppercase(&mut self)
fn make_ascii_uppercase(&mut self)
Converts this CStr
to its ASCII upper case equivalent in-place.
ASCII letters ‘a’ to ‘z’ are mapped to ‘A’ to ‘Z’, but non-ASCII letters are unchanged.
To return a new uppercased value without modifying the existing one, use
to_ascii_uppercase()
.
Sourcefn to_ascii_lowercase(&self) -> Result<CString, AllocError>
fn to_ascii_lowercase(&self) -> Result<CString, AllocError>
Returns a copy of this CString
where each character is mapped to its
ASCII lower case equivalent.
ASCII letters ‘A’ to ‘Z’ are mapped to ‘a’ to ‘z’, but non-ASCII letters are unchanged.
To lowercase the value in-place, use make_ascii_lowercase
.
Sourcefn to_ascii_uppercase(&self) -> Result<CString, AllocError>
fn to_ascii_uppercase(&self) -> Result<CString, AllocError>
Returns a copy of this CString
where each character is mapped to its
ASCII upper case equivalent.
ASCII letters ‘a’ to ‘z’ are mapped to ‘A’ to ‘Z’, but non-ASCII letters are unchanged.
To uppercase the value in-place, use make_ascii_uppercase
.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.