[][src]Struct uapi::Ustring

pub struct Ustring { /* fields omitted */ }

Thin wrapper for a Vec<u8> that has a trailing nul byte

NOTE: Ustring derefs to Ustr derefs to Bstr derefs to [u8]. Rustdoc might not show all available methods.

Ustring is optimized so that it can be created without allocating.

See also the crate documentation.

Implementations

impl Ustring[src]

pub fn new() -> Ustring[src]

Creates a new, empty Ustring

NOTE: This function does not allocate

pub fn reserve(&mut self, num: usize)[src]

Reserves space for num additional bytes in Ustring

See Vec::reserve

pub fn reserve_exact(&mut self, additional: usize)[src]

Reserves space for num additional bytes in Ustring

See Vec::reserve_exact

pub fn capacity(&self) -> usize[src]

Returns the capacity of the underlying Vector excluding the trailing nul byte

pub unsafe fn with_unused<F>(&mut self, f: F) -> Result<usize> where
    F: FnOnce(&mut [u8]) -> Result<usize>, 
[src]

Passes the unused portion of the underlying vector to a callback

The size of the slice is self.capacity() - self.len().

The callback should return the number of bytes written to the the slice. If the callback returns an error, the Ustring is guaranteed to be unchanged.

Safety

  • f must not read from the slice
  • f must initialize the slice up to (excluding) the returned index

pub fn from_vec(s: Vec<u8>) -> Self[src]

Turns s into an Ustring by appending a nul byte.

pub unsafe fn from_vec_with_nul_unchecked(s: Vec<u8>) -> Self[src]

Transmutes the argument into Ustring

Safety

s must be empty or contain a trailing nul byte

pub fn from_vec_with_nul(s: Vec<u8>) -> Result<Self, Vec<u8>>[src]

Checks that s is empty or has a trailing nul byte and then turns it into an Ustring

pub fn into_vec(self) -> Vec<u8>[src]

Returns the underlying Vec<u8> after removing the trailing nul byte

pub fn into_vec_with_nul(self) -> Vec<u8>[src]

Returns the underlying Vec<u8> without removing the trailing nul byte

pub fn from_string(s: String) -> Self[src]

Shortcut for Ustring::from_vec(s.into_bytes())

pub fn from_string_with_nul(s: String) -> Result<Self, String>[src]

Shortcut for Ustring::from_vec_with_nul(s.into_bytes())

pub fn into_string(self) -> Result<String, Self>[src]

Tries to turn self into a String after removing the trailing nul byte

pub fn into_string_with_nul(self) -> Result<String, Self>[src]

Tries to turn self into a String without removing the trailing nul byte

pub fn from_c_string(s: CString) -> Self[src]

Shortcut for Ustring::from_vec(s.into_bytes())

pub fn into_c_string(self) -> Result<CString, (usize, Self)>[src]

Tries to turn self into a CString

On error, the usize is the index of the first interior nul byte.

pub fn from_os_string(s: OsString) -> Self[src]

Shortcut for Ustring::from_vec(s.into_vec())

pub fn from_os_string_with_nul(s: OsString) -> Result<Self, OsString>[src]

Shortcut for Ustring::from_vec_with_nul(s.into_vec())

pub fn into_os_string(self) -> OsString[src]

Shortcut for OsString::from_vec(self.into_vec())

pub fn into_os_string_with_nul(self) -> OsString[src]

Shortcut for OsString::from_vec(self.into_vec_with_nul())

pub fn from_path_buf(s: PathBuf) -> Self[src]

Shortcut for Ustring::from_os_string(s.into_os_string())

pub fn from_path_buf_with_nul(s: PathBuf) -> Result<Self, PathBuf>[src]

Shortcut for Ustring::from_os_string_with_nul(s.into_os_string())

pub fn into_path_buf(self) -> PathBuf[src]

Shortcut for PathBuf::from(self.into_os_string())

pub fn into_path_buf_with_nul(self) -> PathBuf[src]

Shortcut for PathBuf::from(self.into_os_string_with_nul())

pub fn push<T: Bytes + ?Sized>(&mut self, bytes: &T)[src]

Appends the bytes

For example:

let mut s = format_ustr!("hello ");
s.push("world");
assert_eq!("hello world", &s);

pub fn as_ustr(&self) -> &Ustr[src]

Returns self as a &Ustr

pub fn as_ustr_mut(&mut self) -> &mut Ustr[src]

Returns self as a &mut Ustr

Methods from Deref<Target = Ustr>

pub fn is_null(&self) -> bool[src]

Returns true iff this Ustr was constructed via Ustr::null()

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

Transmutes self into &[u8]

pub fn as_c_str(&self) -> Result<&CStr, FromBytesWithNulError>[src]

Shortcut for CStr::from_bytes_with_nul(self.as_bytes_with_nul())

pub fn as_os_str_with_nul(&self) -> &OsStr[src]

Shortcut for OsStr::from_bytes(self.as_bytes_with_nul())

pub fn as_path_with_nul(&self) -> &Path[src]

Shortcut for Path::new(self.as_os_str_with_nul())

pub fn len_with_nul(&self) -> usize[src]

Returns the length of the underlying [u8] including the trailing nul byte

pub fn as_bstr(&self) -> &Bstr[src]

Returns the &Bstr created by dropping the trailing nul byte

pub fn as_bstr_mut(&mut self) -> &mut Bstr[src]

Returns the &mut Bstr created by dropping the trailing nul byte

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

Returns ptr::null() if self.is_null(), otherwise self.as_ptr().

Trait Implementations

impl AsMut<[u8]> for Ustring[src]

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

impl AsRef<OsStr> for Ustring[src]

impl AsRef<Path> for Ustring[src]

impl AsUstr for Ustring[src]

impl Borrow<Bstr> for Ustring[src]

impl Borrow<Ustr> for Ustring[src]

impl Debug for Ustring[src]

impl Default for Ustring[src]

impl Deref for Ustring[src]

type Target = Ustr

The resulting type after dereferencing.

impl DerefMut for Ustring[src]

impl Eq for Ustring[src]

impl From<CString> for Ustring[src]

impl From<OsString> for Ustring[src]

impl From<PathBuf> for Ustring[src]

impl From<String> for Ustring[src]

impl From<Ustring> for Vec<u8>[src]

impl From<Ustring> for OsString[src]

impl From<Ustring> for PathBuf[src]

impl From<Vec<u8>> for Ustring[src]

impl Hash for Ustring[src]

impl<'a> IntoUstr<'a> for &'a Ustring[src]

impl IntoUstr<'static> for Ustring[src]

impl Ord for Ustring[src]

impl PartialEq<[u8]> for Ustring[src]

impl PartialEq<Bstr> for Ustring[src]

impl PartialEq<CStr> for Ustring[src]

impl PartialEq<CString> for Ustring[src]

impl PartialEq<OsStr> for Ustring[src]

impl PartialEq<OsString> for Ustring[src]

impl PartialEq<Path> for Ustring[src]

impl PartialEq<PathBuf> for Ustring[src]

impl PartialEq<String> for Ustring[src]

impl PartialEq<Ustr> for Ustring[src]

impl PartialEq<Ustring> for [u8][src]

impl PartialEq<Ustring> for str[src]

impl PartialEq<Ustring> for Bstr[src]

impl PartialEq<Ustring> for Ustr[src]

impl PartialEq<Ustring> for Ustring[src]

impl PartialEq<Ustring> for CStr[src]

impl PartialEq<Ustring> for OsStr[src]

impl PartialEq<Ustring> for Path[src]

impl PartialEq<Ustring> for Vec<u8>[src]

impl PartialEq<Ustring> for String[src]

impl PartialEq<Ustring> for CString[src]

impl PartialEq<Ustring> for OsString[src]

impl PartialEq<Ustring> for PathBuf[src]

impl PartialEq<Vec<u8>> for Ustring[src]

impl PartialEq<str> for Ustring[src]

impl PartialOrd<Ustring> for Ustring[src]

impl StructuralEq for Ustring[src]

impl StructuralPartialEq for Ustring[src]

impl TryFrom<Ustring> for String[src]

type Error = Ustring

The type returned in the event of a conversion error.

impl TryFrom<Ustring> for CString[src]

type Error = (usize, Ustring)

The type returned in the event of a conversion error.

Auto Trait Implementations

impl RefUnwindSafe for Ustring

impl Send for Ustring

impl Sync for Ustring

impl Unpin for Ustring

impl UnwindSafe for Ustring

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, 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.