pub struct FromVecWithNulError { /* fields omitted */ }
🔬 This is a nightly-only experimental API. (
cstring_from_vec_with_nul
#73179)
Expand description
指示 nul 字节不在预期位置中的错误。
用于创建 CString
的 vector 的末尾必须只有一个 nul 字节。
此错误是由 CString::from_vec_with_nul
方法创建的。
有关更多信息,请参见其文档。
#![feature(cstring_from_vec_with_nul)]
use std::ffi::{CString, FromVecWithNulError};
let _: FromVecWithNulError = CString::from_vec_with_nul(b"f\0oo".to_vec()).unwrap_err();
Run
🔬 This is a nightly-only experimental API. (
cstring_from_vec_with_nul
#73179)
返回试图转换为 CString
的 u8 个字节的片段。
基本用法:
#![feature(cstring_from_vec_with_nul)]
use std::ffi::CString;
let bytes = b"f\0oo".to_vec();
let value = CString::from_vec_with_nul(bytes.clone());
assert_eq!(&bytes[..], value.unwrap_err().as_bytes());
Run
🔬 This is a nightly-only experimental API. (
cstring_from_vec_with_nul
#73179)
返回尝试转换为 CString
的字节。
精心构造此方法以避免分配。
它将消耗错误,将字节移出,因此不需要制作字节的副本。
基本用法:
#![feature(cstring_from_vec_with_nul)]
use std::ffi::CString;
let bytes = b"f\0oo".to_vec();
let value = CString::from_vec_with_nul(bytes.clone());
assert_eq!(bytes, value.unwrap_err().into_bytes());
Run
🔬 This is a nightly-only experimental API. (
backtrace
#53487)
👎 Deprecated since 1.42.0:
use the Display impl or to_string()
👎 Deprecated since 1.33.0:
replaced by Error::source, which can support downcasting
🔬 This is a nightly-only experimental API. (toowned_clone_into
#41263)
recently added