[−][src]Struct const_cstr::ConstCStr
A type representing a static C-compatible string, wrapping &'static str
.
Note
Prefer the const_cstr!
macro to create an instance of this struct
over manual initialization. The macro will include the NUL byte for you.
Fields
val: &'static str
The wrapped string value. Not intended to be used for manual initialization.
Public only to allow initialization by the const_cstr!
macro.
Includes the NUL terminating byte. Use to_str()
to get an &'static str
without the NUL terminating byte.
Methods
impl ConstCStr
[src]
pub fn to_str(&self) -> &'static str
[src]
Returns the wrapped string, without the NUL terminating byte.
Compare to CStr::to_str()
which checks that the string is valid UTF-8 first,
since it starts from an arbitrary pointer instead of a Rust string slice.
pub fn to_bytes(&self) -> &'static [u8]
[src]
Returns the wrapped string as a byte slice, without the NUL terminating byte.
pub fn to_bytes_with_nul(&self) -> &'static [u8]
[src]
Returns the wrapped string as a byte slice, with* the NUL terminating byte.
pub fn as_ptr(&self) -> *const c_char
[src]
Returns a pointer to the beginning of the wrapped string.
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.
Panics
If the wrapped string is not NUL-terminated.
(Unlikely if you used the const_cstr!
macro. This is just a sanity check.)
pub fn as_cstr(&self) -> &'static CStr
[src]
Returns the wrapped string as an &'static CStr
, skipping the length check that
CStr::from_ptr()
performs (since we know the length already).
Panics
If the wrapped string is not NUL-terminated.
(Unlikely if you used the const_cstr!
macro. This is just a sanity check.)
Trait Implementations
impl Clone for ConstCStr
[src]
impl Copy for ConstCStr
[src]
impl Debug for ConstCStr
[src]
impl Eq for ConstCStr
[src]
impl Hash for ConstCStr
[src]
fn hash<__H: Hasher>(&self, state: &mut __H)
[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl Ord for ConstCStr
[src]
fn cmp(&self, other: &ConstCStr) -> Ordering
[src]
fn max(self, other: Self) -> Self
1.21.0[src]
fn min(self, other: Self) -> Self
1.21.0[src]
fn clamp(self, min: Self, max: Self) -> Self
[src]
impl PartialEq<ConstCStr> for ConstCStr
[src]
impl PartialOrd<ConstCStr> for ConstCStr
[src]
fn partial_cmp(&self, other: &ConstCStr) -> Option<Ordering>
[src]
fn lt(&self, other: &ConstCStr) -> bool
[src]
fn le(&self, other: &ConstCStr) -> bool
[src]
fn gt(&self, other: &ConstCStr) -> bool
[src]
fn ge(&self, other: &ConstCStr) -> bool
[src]
impl StructuralEq for ConstCStr
[src]
impl StructuralPartialEq for ConstCStr
[src]
Auto Trait Implementations
impl RefUnwindSafe for ConstCStr
impl Send for ConstCStr
impl Sync for ConstCStr
impl Unpin for ConstCStr
impl UnwindSafe for ConstCStr
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,