Struct c_utf8::CUtf8Buf [−][src]
pub struct CUtf8Buf(_);
An owned, mutable UTF-8 encoded C string (akin to String
or
PathBuf
).
Examples
This type retains certain behaviors that are expected from String
such
as calling .collect()
on iterators.
use c_utf8::CUtf8Buf; let strings = vec![ "Hello ", "there, ", "fellow ", "human!" ]; let joined = strings.into_iter().collect::<CUtf8Buf>(); let bytes = joined.as_bytes_with_nul(); assert_eq!(bytes, b"Hello there, fellow human!\0");
Methods
impl CUtf8Buf
[src]
impl CUtf8Buf
pub fn new() -> CUtf8Buf
[src]
pub fn new() -> CUtf8Buf
Creates a new empty CUtf8Buf
.
pub fn from_string(s: String) -> CUtf8Buf
[src]
pub fn from_string(s: String) -> CUtf8Buf
Creates a new C string from a UTF-8 string, appending a nul terminator if one doesn't already exist.
pub unsafe fn from_string_unchecked(s: String) -> CUtf8Buf
[src]
pub unsafe fn from_string_unchecked(s: String) -> CUtf8Buf
Creates a new C string from a native Rust string without checking for a nul terminator.
pub fn push_str(&mut self, s: &str)
[src]
pub fn push_str(&mut self, s: &str)
Appends a given string slice onto the end of this CUtf8Buf
.
pub fn push(&mut self, c: char)
[src]
pub fn push(&mut self, c: char)
Appends the given char
to the end of this CUtf8Buf
.
pub fn into_string(self) -> String
[src]
pub fn into_string(self) -> String
Converts self
into a native UTF-8 encoded Rust
String
.
pub fn into_bytes(self) -> Vec<u8>
[src]
pub fn into_bytes(self) -> Vec<u8>
Converts self
into its underlying bytes.
Methods from Deref<Target = CUtf8>
pub const EMPTY: &'static CUtf8
pub fn len(&self) -> usize
[src]
pub fn len(&self) -> usize
Returns the number of bytes without taking into account the trailing nul byte.
This behavior is the same as that of
str::len
where the length is not measured in
char
s.
Examples
Basic usage:
let s = c_utf8!("Hey"); assert_eq!(s.len(), 3);
pub fn is_empty(&self) -> bool
[src]
pub fn is_empty(&self) -> bool
Returns true
if self
contains 0 bytes, disregarding the trailing nul
byte.
Examples
Basic usage:
let s = c_utf8::CUtf8::EMPTY; assert!(s.is_empty()); assert_eq!(s.len(), 0);
pub fn as_ptr(&self) -> *const c_char
[src]
pub fn as_ptr(&self) -> *const c_char
Returns a pointer to the start of the raw C string.
pub fn as_c_str(&self) -> &CStr
[src]
pub fn as_c_str(&self) -> &CStr
Returns self
as a normal C string.
pub fn as_str(&self) -> &str
[src]
pub fn as_str(&self) -> &str
Returns self
as a normal UTF-8 encoded string.
pub fn as_str_with_nul(&self) -> &str
[src]
pub fn as_str_with_nul(&self) -> &str
Returns self
as a UTF-8 encoded string with a trailing 0 byte.
pub fn as_bytes(&self) -> &[u8]
[src]
pub fn as_bytes(&self) -> &[u8]
Returns the bytes of self
without a trailing 0 byte.
pub fn as_bytes_with_nul(&self) -> &[u8]
[src]
pub fn as_bytes_with_nul(&self) -> &[u8]
Returns the bytes of self
with a trailing 0 byte.
Trait Implementations
impl Clone for CUtf8Buf
[src]
impl Clone for CUtf8Buf
fn clone(&self) -> CUtf8Buf
[src]
fn clone(&self) -> CUtf8Buf
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
impl PartialEq for CUtf8Buf
[src]
impl PartialEq for CUtf8Buf
fn eq(&self, other: &CUtf8Buf) -> bool
[src]
fn eq(&self, other: &CUtf8Buf) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &CUtf8Buf) -> bool
[src]
fn ne(&self, other: &CUtf8Buf) -> bool
This method tests for !=
.
impl Eq for CUtf8Buf
[src]
impl Eq for CUtf8Buf
impl Hash for CUtf8Buf
[src]
impl Hash for CUtf8Buf
fn hash<__H: Hasher>(&self, state: &mut __H)
[src]
fn hash<__H: Hasher>(&self, state: &mut __H)
Feeds this value into the given [Hasher
]. Read more
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
Feeds a slice of this type into the given [Hasher
]. Read more
impl PartialOrd for CUtf8Buf
[src]
impl PartialOrd for CUtf8Buf
fn partial_cmp(&self, other: &CUtf8Buf) -> Option<Ordering>
[src]
fn partial_cmp(&self, other: &CUtf8Buf) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
fn lt(&self, other: &CUtf8Buf) -> bool
[src]
fn lt(&self, other: &CUtf8Buf) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
fn le(&self, other: &CUtf8Buf) -> bool
[src]
fn le(&self, other: &CUtf8Buf) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
fn gt(&self, other: &CUtf8Buf) -> bool
[src]
fn gt(&self, other: &CUtf8Buf) -> bool
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
fn ge(&self, other: &CUtf8Buf) -> bool
[src]
fn ge(&self, other: &CUtf8Buf) -> bool
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
impl Ord for CUtf8Buf
[src]
impl Ord for CUtf8Buf
fn cmp(&self, other: &CUtf8Buf) -> Ordering
[src]
fn cmp(&self, other: &CUtf8Buf) -> Ordering
This method returns an Ordering
between self
and other
. Read more
fn max(self, other: Self) -> Self
1.21.0[src]
fn max(self, other: Self) -> Self
Compares and returns the maximum of two values. Read more
fn min(self, other: Self) -> Self
1.21.0[src]
fn min(self, other: Self) -> Self
Compares and returns the minimum of two values. Read more
impl PartialEq<CUtf8> for CUtf8Buf
[src]
impl PartialEq<CUtf8> for CUtf8Buf
fn eq(&self, other: &CUtf8) -> bool
[src]
fn eq(&self, other: &CUtf8) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
fn ne(&self, other: &Rhs) -> bool
This method tests for !=
.
impl PartialEq<CUtf8Buf> for CUtf8
[src]
impl PartialEq<CUtf8Buf> for CUtf8
fn eq(&self, other: &CUtf8Buf) -> bool
[src]
fn eq(&self, other: &CUtf8Buf) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
fn ne(&self, other: &Rhs) -> bool
This method tests for !=
.
impl Default for CUtf8Buf
[src]
impl Default for CUtf8Buf
impl Deref for CUtf8Buf
[src]
impl Deref for CUtf8Buf
type Target = CUtf8
The resulting type after dereferencing.
fn deref(&self) -> &CUtf8
[src]
fn deref(&self) -> &CUtf8
Dereferences the value.
impl DerefMut for CUtf8Buf
[src]
impl DerefMut for CUtf8Buf
impl<T> FromIterator<T> for CUtf8Buf where
String: FromIterator<T>,
[src]
impl<T> FromIterator<T> for CUtf8Buf where
String: FromIterator<T>,
fn from_iter<I: IntoIterator<Item = T>>(it: I) -> CUtf8Buf
[src]
fn from_iter<I: IntoIterator<Item = T>>(it: I) -> CUtf8Buf
Creates a value from an iterator. Read more
impl Debug for CUtf8Buf
[src]
impl Debug for CUtf8Buf
fn fmt(&self, f: &mut Formatter) -> Result
[src]
fn fmt(&self, f: &mut Formatter) -> Result
Formats the value using the given formatter. Read more
impl Display for CUtf8Buf
[src]
impl Display for CUtf8Buf
fn fmt(&self, f: &mut Formatter) -> Result
[src]
fn fmt(&self, f: &mut Formatter) -> Result
Formats the value using the given formatter. Read more
impl Write for CUtf8Buf
[src]
impl Write for CUtf8Buf
fn write_str(&mut self, s: &str) -> Result
[src]
fn write_str(&mut self, s: &str) -> Result
Writes a slice of bytes into this writer, returning whether the write succeeded. Read more
fn write_char(&mut self, c: char) -> Result
[src]
fn write_char(&mut self, c: char) -> Result
Writes a [char
] into this writer, returning whether the write succeeded. Read more
fn write_fmt(&mut self, args: Arguments) -> Result
[src]
fn write_fmt(&mut self, args: Arguments) -> Result
Glue for usage of the [write!
] macro with implementors of this trait. Read more
impl Borrow<CUtf8> for CUtf8Buf
[src]
impl Borrow<CUtf8> for CUtf8Buf
impl BorrowMut<CUtf8> for CUtf8Buf
[src]
impl BorrowMut<CUtf8> for CUtf8Buf
fn borrow_mut(&mut self) -> &mut CUtf8
[src]
fn borrow_mut(&mut self) -> &mut CUtf8
Mutably borrows from an owned value. Read more
impl AsRef<CUtf8> for CUtf8Buf
[src]
impl AsRef<CUtf8> for CUtf8Buf
impl AsMut<CUtf8> for CUtf8Buf
[src]
impl AsMut<CUtf8> for CUtf8Buf
impl<'a> From<&'a CUtf8> for CUtf8Buf
[src]
impl<'a> From<&'a CUtf8> for CUtf8Buf
impl<'a> From<&'a mut CUtf8> for CUtf8Buf
[src]
impl<'a> From<&'a mut CUtf8> for CUtf8Buf
impl From<String> for CUtf8Buf
[src]
impl From<String> for CUtf8Buf
impl<'a> From<&'a str> for CUtf8Buf
[src]
impl<'a> From<&'a str> for CUtf8Buf
impl<'a> From<&'a mut str> for CUtf8Buf
[src]
impl<'a> From<&'a mut str> for CUtf8Buf
impl From<Box<CUtf8>> for CUtf8Buf
[src]
impl From<Box<CUtf8>> for CUtf8Buf
impl From<CUtf8Buf> for Box<CUtf8>
[src]
impl From<CUtf8Buf> for Box<CUtf8>
impl From<CUtf8Buf> for String
[src]
impl From<CUtf8Buf> for String
impl From<CUtf8Buf> for Vec<u8>
[src]
impl From<CUtf8Buf> for Vec<u8>