pub struct StaticCString<const N: usize> { /* private fields */ }Expand description
A C-compatible, growable but fixed-capacity string.
The exact encoding of the string depends on the target platform.
The StaticCString guarantees a null-terminator at the end, so the maximum length is 1 less than capacity.
Implementations§
Source§impl<const N: usize> StaticCString<N>
impl<const N: usize> StaticCString<N>
Sourcepub const fn new() -> Self
pub const fn new() -> Self
Creates a new empty StaticCString.
Given that the string is empty, the buffer that contains the string isn’t initialized. This means the initial operation is very inexpensive.
§Example
use static_collections::ffi::c_str::StaticCString;
let s:StaticCString<32>=StaticCString::from(c"Hello, World!");
assert_eq!(s.len(),13);Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the length of the static-string by using strnlen.
§Example
use static_collections::ffi::c_str::StaticCString;
let s:StaticCString<32>=StaticCString::from(c"Hello, World!");
assert_eq!(s.len(),13);pub fn is_empty(&self) -> bool
Sourcepub const fn capacity(&self) -> usize
pub const fn capacity(&self) -> usize
Returns the capacity of the static-string.
§Example
use static_collections::ffi::c_str::StaticCString;
let s:StaticCString<32>=StaticCString::from(c"Hello, World!");
assert_eq!(s.capacity(),32);Sourcepub const fn as_ptr(&self) -> *const i8
pub const fn as_ptr(&self) -> *const i8
Returns the immutable pointer to the first character.
The returned pointer can be passed to C-FFI routines that accepts raw pointers.
Sourcepub const fn as_mut_ptr(&mut self) -> *mut i8
pub const fn as_mut_ptr(&mut self) -> *mut i8
Returns the mutable pointer to the first character.
The returned pointer can be passed to C-FFI routines that accepts raw pointers.
Sourcepub fn as_bytes(&self) -> &[u8]
pub fn as_bytes(&self) -> &[u8]
Returns the contents of this StaticCString as a slice of bytes.
The returned slice does not contain the trailing null-terminator, and it is
guaranteed to not contain any interior null bytes. If you need this null-terminator,
use StaticCString::as_bytes_with_nul instead.
Sourcepub fn as_mut_bytes(&mut self) -> &mut [u8]
pub fn as_mut_bytes(&mut self) -> &mut [u8]
Returns the contents of this StaticCString as a mutable slice of bytes.
The returned slice does not contain the trailing null-terminator, and it is
guaranteed to not contain any interior null bytes. If you need this null-terminator,
use StaticCString::as_mut_bytes_with_nul instead.
Sourcepub fn as_bytes_with_nul(&self) -> &[u8]
pub fn as_bytes_with_nul(&self) -> &[u8]
Returns the contents of this StaticCString as a slice of bytes, including the trailing null-terminator.
Sourcepub unsafe fn as_mut_bytes_with_nul(&mut self) -> &mut [u8]
pub unsafe fn as_mut_bytes_with_nul(&mut self) -> &mut [u8]
Returns the contents of this StaticCString as a slice of bytes, including the trailing null-terminator.
§Safety
You must ensure the slice contains a null-terminator throughout the lifetime of the slice.
pub fn as_c_str(&self) -> &CStr
Source§impl<'a, const N: usize> StaticCString<N>
impl<'a, const N: usize> StaticCString<N>
pub fn from_raw_ptr(ptr: *const i8) -> Result<&'a Self, NotNullTerminatedError>
pub fn from_raw_mut_ptr( ptr: *mut i8, ) -> Result<&'a mut Self, NotNullTerminatedError>
Trait Implementations§
Source§impl<const M: usize, const N: usize> AddAssign<StaticCString<M>> for StaticCString<N>
impl<const M: usize, const N: usize> AddAssign<StaticCString<M>> for StaticCString<N>
Source§fn add_assign(&mut self, rhs: StaticCString<M>)
fn add_assign(&mut self, rhs: StaticCString<M>)
+= operation. Read moreSource§impl<const N: usize> Clone for StaticCString<N>
impl<const N: usize> Clone for StaticCString<N>
Source§fn clone(&self) -> StaticCString<N>
fn clone(&self) -> StaticCString<N>
1.0.0§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<const N: usize> Debug for StaticCString<N>
impl<const N: usize> Debug for StaticCString<N>
Source§impl<const N: usize> Default for StaticCString<N>
impl<const N: usize> Default for StaticCString<N>
Source§impl<const M: usize, const N: usize> PartialEq<StaticCString<M>> for StaticCString<N>
impl<const M: usize, const N: usize> PartialEq<StaticCString<M>> for StaticCString<N>
Source§impl<const M: usize, const N: usize> PartialOrd<StaticCString<M>> for StaticCString<N>
impl<const M: usize, const N: usize> PartialOrd<StaticCString<M>> for StaticCString<N>
impl<const N: usize> Send for StaticCString<N>
impl<const N: usize> Sync for StaticCString<N>
Auto Trait Implementations§
impl<const N: usize> Freeze for StaticCString<N>
impl<const N: usize> RefUnwindSafe for StaticCString<N>
impl<const N: usize> Unpin for StaticCString<N>
impl<const N: usize> UnwindSafe for StaticCString<N>
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
clone_to_uninit)