pub trait CStr:
Deref<Target = CStr>
+ Display
+ Debug
+ Send
+ Sync {
// Required methods
fn as_cstr(&self) -> &StdCStr;
fn dyn_clone(&self) -> Box<dyn CStr>;
// Provided methods
fn as_bytes(&self) -> &[u8] ⓘ { ... }
fn as_bytes_with_nul(&self) -> &[u8] ⓘ { ... }
fn as_ptr(&self) -> *const c_char { ... }
fn len(&self) -> usize { ... }
fn is_empty(&self) -> bool { ... }
}Available on crate features
types-cstr and types only.Expand description
安全 C 字符串的统一接口:只读视图,内部恒为合法 CStr(以 \0 结尾、无内部 NUL)。
注意:本 trait 名为 CStr,与 core::ffi::CStr 同名。取值时用
CStr::as_cstr 拿到底层 &core::ffi::CStr。
§Feature Requirement
需要启用 "types-cstr" 特性。
§Examples
use core::convert::TryInto;
use lib_unknown::types::cstr::{CStr, StackCStr};
let s: StackCStr<8> = "hi".try_into().unwrap();
assert_eq!(s.as_cstr().to_bytes(), b"hi");
assert_eq!(s.len(), 2);Required Methods§
Provided Methods§
Sourcefn as_bytes_with_nul(&self) -> &[u8] ⓘ
fn as_bytes_with_nul(&self) -> &[u8] ⓘ
Trait Implementations§
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".