use std::ffi::CStr; let cstr = CStr::from_bytes_with_nul(b"hello\0"); assert!(cstr.is_ok()); 创建没有尾随 nul 终止符的 CStr 是错误的: use std::ffi::CStr; let cstr = CStr::from_bytes_with_nul(b"hello"); assert!(cstr.is_err()); 创建带有内部 nul 字节的 CStr 是一个错误...
FromBytesWithNulErroris a struct that only containskind: FromBytesWithNulErrorKind, which is an enum. This representation is somewhat redundant. MakeFromBytesWithNulErroran enum that is equivalent to currentFromBytesWithNulErrorKindin order to simplify. Additionally, add docs for the enum members. ...
This PR renames the former kind enum from FromBytesWithNulErrorKind to FromBytesWithNulError, and removes the original struct. See rust-lang/libs-team#493 Possible Changes - TBD should the new en...
pub fn as_bytes(&self) -> &[u8] 返回尝试转换为 CString 的 u8 s 字节的切片。 例子 基本用法: 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....
它将消耗错误,移出字节,因此不需要制作字节的副本。 例子 基本用法: 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());...