FromVecWithNulError in alloc::ffi - Rust
source link: https://doc.rust-lang.org/stable/alloc/ffi/struct.FromVecWithNulError.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Implementations
1.58.0 · source
pub fn as_bytes(&self) -> &[u8]
Returns a slice of u8
s bytes that were attempted to convert to a CString
.
Examples
Basic usage:
use std::ffi::CString;
// Some invalid bytes in a vector
let bytes = b"f\0oo".to_vec();
let value = CString::from_vec_with_nul(bytes.clone());
assert_eq!(&bytes[..], value.unwrap_err().as_bytes());
Run1.58.0 · source
pub fn into_bytes(self) -> Vec<u8>
Returns the bytes that were attempted to convert to a CString
.
This method is carefully constructed to avoid allocation. It will consume the error, moving out the bytes, so that a copy of the bytes does not need to be made.
Examples
Basic usage:
use std::ffi::CString;
// Some invalid bytes in a vector
let bytes = b"f\0oo".to_vec();
let value = CString::from_vec_with_nul(bytes.clone());
assert_eq!(bytes, value.unwrap_err().into_bytes());
RunRecommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK