[−][src]Struct uapi::Ustring
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 [MaybeUninit<u8>]) -> Result<usize>, [src]
F: FnOnce(&mut [MaybeUninit<u8>]) -> Result<usize>,
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
fmust not read from the slicefmust 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]
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]
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, Global>> for Ustring[src]
impl Hash for Ustring[src]
pub fn hash<__H: Hasher>(&self, state: &mut __H)[src]
pub fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher, 1.3.0[src]
H: Hasher,
impl<'a> IntoUstr<'a> for &'a Ustring[src]
impl IntoUstr<'static> for Ustring[src]
impl Ord for Ustring[src]
pub fn cmp(&self, other: &Ustring) -> Ordering[src]
#[must_use]pub fn max(self, other: Self) -> Self1.21.0[src]
#[must_use]pub fn min(self, other: Self) -> Self1.21.0[src]
#[must_use]pub fn clamp(self, min: Self, max: Self) -> Self1.50.0[src]
impl PartialEq<[u8]> for Ustring[src]
pub fn eq(&self, other: &[u8]) -> bool[src]
#[must_use]pub fn ne(&self, other: &Rhs) -> bool1.0.0[src]
impl PartialEq<Bstr> for Ustring[src]
pub fn eq(&self, other: &Bstr) -> bool[src]
#[must_use]pub fn ne(&self, other: &Rhs) -> bool1.0.0[src]
impl PartialEq<CStr> for Ustring[src]
pub fn eq(&self, other: &CStr) -> bool[src]
#[must_use]pub fn ne(&self, other: &Rhs) -> bool1.0.0[src]
impl PartialEq<CString> for Ustring[src]
pub fn eq(&self, other: &CString) -> bool[src]
#[must_use]pub fn ne(&self, other: &Rhs) -> bool1.0.0[src]
impl PartialEq<OsStr> for Ustring[src]
pub fn eq(&self, other: &OsStr) -> bool[src]
#[must_use]pub fn ne(&self, other: &Rhs) -> bool1.0.0[src]
impl PartialEq<OsString> for Ustring[src]
pub fn eq(&self, other: &OsString) -> bool[src]
#[must_use]pub fn ne(&self, other: &Rhs) -> bool1.0.0[src]
impl PartialEq<Path> for Ustring[src]
pub fn eq(&self, other: &Path) -> bool[src]
#[must_use]pub fn ne(&self, other: &Rhs) -> bool1.0.0[src]
impl PartialEq<PathBuf> for Ustring[src]
pub fn eq(&self, other: &PathBuf) -> bool[src]
#[must_use]pub fn ne(&self, other: &Rhs) -> bool1.0.0[src]
impl PartialEq<String> for Ustring[src]
pub fn eq(&self, other: &String) -> bool[src]
#[must_use]pub fn ne(&self, other: &Rhs) -> bool1.0.0[src]
impl PartialEq<Ustr> for Ustring[src]
pub fn eq(&self, other: &Ustr) -> bool[src]
#[must_use]pub fn ne(&self, other: &Rhs) -> bool1.0.0[src]
impl PartialEq<Ustring> for [u8][src]
pub fn eq(&self, other: &Ustring) -> bool[src]
#[must_use]pub fn ne(&self, other: &Rhs) -> bool1.0.0[src]
impl PartialEq<Ustring> for str[src]
pub fn eq(&self, other: &Ustring) -> bool[src]
#[must_use]pub fn ne(&self, other: &Rhs) -> bool1.0.0[src]
impl PartialEq<Ustring> for Bstr[src]
pub fn eq(&self, other: &Ustring) -> bool[src]
#[must_use]pub fn ne(&self, other: &Rhs) -> bool1.0.0[src]
impl PartialEq<Ustring> for Ustr[src]
pub fn eq(&self, other: &Ustring) -> bool[src]
#[must_use]pub fn ne(&self, other: &Rhs) -> bool1.0.0[src]
impl PartialEq<Ustring> for Ustring[src]
impl PartialEq<Ustring> for CStr[src]
pub fn eq(&self, other: &Ustring) -> bool[src]
#[must_use]pub fn ne(&self, other: &Rhs) -> bool1.0.0[src]
impl PartialEq<Ustring> for OsStr[src]
pub fn eq(&self, other: &Ustring) -> bool[src]
#[must_use]pub fn ne(&self, other: &Rhs) -> bool1.0.0[src]
impl PartialEq<Ustring> for Path[src]
pub fn eq(&self, other: &Ustring) -> bool[src]
#[must_use]pub fn ne(&self, other: &Rhs) -> bool1.0.0[src]
impl PartialEq<Ustring> for Vec<u8>[src]
pub fn eq(&self, other: &Ustring) -> bool[src]
#[must_use]pub fn ne(&self, other: &Rhs) -> bool1.0.0[src]
impl PartialEq<Ustring> for String[src]
pub fn eq(&self, other: &Ustring) -> bool[src]
#[must_use]pub fn ne(&self, other: &Rhs) -> bool1.0.0[src]
impl PartialEq<Ustring> for CString[src]
pub fn eq(&self, other: &Ustring) -> bool[src]
#[must_use]pub fn ne(&self, other: &Rhs) -> bool1.0.0[src]
impl PartialEq<Ustring> for OsString[src]
pub fn eq(&self, other: &Ustring) -> bool[src]
#[must_use]pub fn ne(&self, other: &Rhs) -> bool1.0.0[src]
impl PartialEq<Ustring> for PathBuf[src]
pub fn eq(&self, other: &Ustring) -> bool[src]
#[must_use]pub fn ne(&self, other: &Rhs) -> bool1.0.0[src]
impl PartialEq<Vec<u8, Global>> for Ustring[src]
pub fn eq(&self, other: &Vec<u8>) -> bool[src]
#[must_use]pub fn ne(&self, other: &Rhs) -> bool1.0.0[src]
impl PartialEq<str> for Ustring[src]
pub fn eq(&self, other: &str) -> bool[src]
#[must_use]pub fn ne(&self, other: &Rhs) -> bool1.0.0[src]
impl PartialOrd<Ustring> for Ustring[src]
pub fn partial_cmp(&self, other: &Ustring) -> Option<Ordering>[src]
pub fn lt(&self, other: &Ustring) -> bool[src]
pub fn le(&self, other: &Ustring) -> bool[src]
pub fn gt(&self, other: &Ustring) -> bool[src]
pub fn ge(&self, other: &Ustring) -> bool[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.
pub fn try_from(value: Ustring) -> Result<Self, Self::Error>[src]
impl TryFrom<Ustring> for CString[src]
Auto Trait Implementations
impl RefUnwindSafe for Ustring[src]
impl Send for Ustring[src]
impl Sync for Ustring[src]
impl Unpin for Ustring[src]
impl UnwindSafe for Ustring[src]
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,
pub 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, 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.
pub 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>,