pub struct CRStr(/* private fields */);Implementations§
Source§impl CRStr
impl CRStr
Sourcepub const fn new(data: &'static str) -> Result<Self, CRStrError>
pub const fn new(data: &'static str) -> Result<Self, CRStrError>
Validate that an input UTF-8 string is null-terminated, and attempt to construct references to each kind of string.
To use, an input string must be null-terminated:
let my_crstr = CRStr::new("some text\0").unwrap();
let str: &str = my_crstr.as_ref();
let cstr: &CStr = my_crstr.as_ref();
assert_eq!(str, "some text");
assert_eq!(cstr, c"some text");
let will_fail = CRStr::new("not null-terminated");
assert!(will_fail.is_err());Sourcepub const fn new_unchecked(data: &'static str) -> Self
pub const fn new_unchecked(data: &'static str) -> Self
CRStr::new which panics on an invalid input.
Intended for static/const definitions.
static MY_STR: CRStr = CRStr::new_unchecked("some text\0");
let str: &str = MY_STR.as_ref();
let cstr: &CStr = MY_STR.as_ref();
assert_eq!(str, "some text");
assert_eq!(cstr, c"some text");Trait Implementations§
Source§impl Error for CRStr
impl Error for CRStr
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
👎Deprecated since 1.42.0: use the Display impl or to_string()
impl Copy for CRStr
impl Eq for CRStr
impl StructuralPartialEq for CRStr
Auto Trait Implementations§
impl Freeze for CRStr
impl RefUnwindSafe for CRStr
impl Send for CRStr
impl Sync for CRStr
impl Unpin for CRStr
impl UnwindSafe for CRStr
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more