Trait CStrExt

Source
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§

Source

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.

Source

unsafe fn from_bytes_with_nul_unchecked_mut(bytes: &mut [u8]) -> &mut Self

Creates a mutable CStr from a [u8] without performing any additional checks.

§Safety

bytes must end with a NUL byte, and should only have a single NUL byte (or the string will be truncated).

Source

fn as_char_ptr(&self) -> *const c_char

Returns a C pointer to the string.

Source

fn to_cstring(&self) -> Result<CString, AllocError>

Convert this CStr into a CString by allocating memory and copying over the string data.

Source

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().

Source

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().

Source

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.

Source

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.

Implementors§