Trait IntoCStr

Source
pub trait IntoCStr: Sized {
    type Temp: Deref<Target = CStr>;

    // Required methods
    fn into(self) -> Self::Temp;
    fn into_cstring(self) -> CString;
    fn len(&self) -> usize;

    // Provided methods
    fn is_empty(&self) -> bool { ... }
    unsafe fn push_to_non_null_vec(self, bs: &mut Vec<u8>) { ... }
}
Expand description

Represents any type that can be converted into something that can be deref’ed to a &CStr.

Required Associated Types§

Source

type Temp: Deref<Target = CStr>

The type that can actually be converted into a CStr.

Required Methods§

Source

fn into(self) -> Self::Temp

Convert this value into a Temp that can be converted into a CStr.

Source

fn into_cstring(self) -> CString

Convert this value directly into a CString.

Source

fn len(&self) -> usize

Length in bytes of the CString within.

Provided Methods§

Source

fn is_empty(&self) -> bool

Checks whether the string is empty.

Source

unsafe fn push_to_non_null_vec(self, bs: &mut Vec<u8>)

Adds the bytes of the CStr within to the given Vec.

SAFETY: Unsafe because we will not check there are no NULs. Reimplement this if fn into() does extra allocations.

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.

Implementations on Foreign Types§

Source§

impl IntoCStr for &str

Source§

type Temp = CString

Source§

fn into(self) -> Self::Temp

Source§

fn into_cstring(self) -> CString

Source§

fn len(&self) -> usize

Source§

unsafe fn push_to_non_null_vec(self, bs: &mut Vec<u8>)

Source§

impl IntoCStr for &String

Source§

type Temp = CString

Source§

fn into(self) -> Self::Temp

Source§

fn into_cstring(self) -> CString

Source§

fn len(&self) -> usize

Source§

unsafe fn push_to_non_null_vec(self, bs: &mut Vec<u8>)

Source§

impl IntoCStr for &CStr

Source§

type Temp = &CStr

Source§

fn into(self) -> Self

Source§

fn into_cstring(self) -> CString

Source§

fn len(&self) -> usize

Source§

impl IntoCStr for CString

Source§

type Temp = CString

Source§

fn into(self) -> Self

Source§

fn into_cstring(self) -> CString

Source§

fn len(&self) -> usize

Source§

impl IntoCStr for String

Source§

type Temp = CString

Source§

fn into(self) -> Self::Temp

Source§

fn into_cstring(self) -> CString

Source§

fn len(&self) -> usize

Source§

impl<'a> IntoCStr for &'a CString

Source§

type Temp = &'a CStr

Source§

fn into(self) -> &'a CStr

Source§

fn into_cstring(self) -> CString

Source§

fn len(&self) -> usize

Source§

impl<'a, B> IntoCStr for Cow<'a, B>
where B: 'a + ToOwned + ?Sized, &'a B: IntoCStr, B::Owned: IntoCStr, <&'a B as IntoCStr>::Temp: Into<Cow<'a, CStr>>,

Source§

type Temp = Cow<'a, CStr>

Source§

fn into(self) -> Cow<'a, CStr>

Source§

fn into_cstring(self) -> CString

Source§

fn len(&self) -> usize

Implementors§