netcorehost/pdcstring/impl/
traits.rs

1use std::{
2    error::Error,
3    ffi::{OsStr, OsString},
4    fmt::{Debug, Display},
5};
6
7use crate::pdcstring::{ContainsNul, MissingNulTerminator, PdChar, PdUChar, ToStringError};
8
9pub(crate) trait PdCStringInner
10where
11    Self: Sized,
12{
13    fn from_str(s: impl AsRef<str>) -> Result<Self, ContainsNul>;
14    fn from_os_str(s: impl AsRef<OsStr>) -> Result<Self, ContainsNul>;
15    unsafe fn from_str_ptr(ptr: *const PdChar) -> Self;
16    fn from_vec(vec: impl Into<Vec<PdUChar>>) -> Result<Self, ContainsNul>;
17    fn into_vec(self) -> Vec<PdUChar>;
18    fn into_vec_with_nul(self) -> Vec<PdUChar>;
19}
20
21pub(crate) trait PdCStrInner {
22    fn as_ptr(&self) -> *const PdChar;
23    unsafe fn from_str_ptr<'a>(ptr: *const PdChar) -> &'a Self;
24    unsafe fn from_slice_with_nul_unchecked(slice: &[PdUChar]) -> &Self;
25    fn to_os_string(&self) -> OsString;
26    fn from_slice_with_nul(slice: &[PdUChar]) -> Result<&Self, MissingNulTerminator>;
27    fn as_slice(&self) -> &[PdUChar];
28    fn as_slice_with_nul(&self) -> &[PdUChar];
29    fn is_empty(&self) -> bool;
30    fn len(&self) -> usize;
31    fn to_string(&self) -> Result<String, ToStringError>;
32    fn to_string_lossy(&self) -> String;
33}
34
35pub(crate) trait ToStringErrorInner: Debug + Display + Error + Clone {
36    fn index(&self) -> Option<usize>;
37}
38
39#[allow(dead_code)]
40pub(crate) trait MissingNulTerminatorInner: Debug + Display + Error + Clone {}