[][src]Struct zombiezen_const_cstr::ConstCStr

pub struct ConstCStr { /* fields omitted */ }

A reference to a C-compatible string constant.

Implementations

impl ConstCStr[src]

pub const unsafe fn from_str_with_nul_unchecked(val: &'static str) -> ConstCStr[src]

Unsafely creates a constant C string reference from a string slice.

Prefer using the const_cstr! macro than calling this function directly.

Safety

The provided slice must be NUL-terminated and not contain any interior NUL bytes.

Examples

use zombiezen_const_cstr::ConstCStr;

let s = unsafe { ConstCStr::from_str_with_nul_unchecked("foo\0") };
assert_eq!(s.as_str(), "foo");

pub fn as_str(self) -> &'static str[src]

Returns the referenced string without the terminating NUL byte.

pub fn as_bytes(self) -> &'static [u8][src]

Returns the referenced string as a byte slice without the terminating NUL byte.

pub const fn as_bytes_with_nul(self) -> &'static [u8][src]

Returns the referenced string as a byte slice, with the NUL terminating byte.

pub const fn as_ptr(self) -> *const c_char[src]

Returns a pointer to the beginning of the string constant.

Suitable for passing to any function that expects a C-compatible string. Since the underlying string is guaranteed to be 'static, the pointer should always be valid.

pub fn as_cstr(self) -> &'static CStr[src]

Returns &'static CStr to the referenced string.

Trait Implementations

impl AsRef<[u8]> for ConstCStr[src]

impl AsRef<CStr> for ConstCStr[src]

impl AsRef<str> for ConstCStr[src]

impl Clone for ConstCStr[src]

impl Copy for ConstCStr[src]

impl Debug for ConstCStr[src]

impl Default for ConstCStr[src]

fn default() -> ConstCStr[src]

Returns an empty C string constant.

impl Display for ConstCStr[src]

impl Eq for ConstCStr[src]

impl From<ConstCStr> for &'static str[src]

impl From<ConstCStr> for &'static [u8][src]

impl From<ConstCStr> for *const c_char[src]

impl From<ConstCStr> for &'static CStr[src]

impl Hash for ConstCStr[src]

impl Ord for ConstCStr[src]

impl PartialEq<ConstCStr> for ConstCStr[src]

impl PartialOrd<ConstCStr> for ConstCStr[src]

impl StructuralEq for ConstCStr[src]

impl StructuralPartialEq for ConstCStr[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.