@@ -3,10 +3,11 @@ use super::UnalignedSlice;
3
3
use crate :: polyfill:: maybe_uninit_slice_assume_init_ref;
4
4
use core:: borrow:: Borrow ;
5
5
use core:: ffi:: CStr ;
6
+ use core:: fmt:: { self , Display , Formatter } ;
6
7
use core:: iter:: Iterator ;
7
8
use core:: mem:: MaybeUninit ;
8
9
use core:: result:: Result ;
9
- use core:: { fmt , slice} ;
10
+ use core:: slice;
10
11
11
12
#[ cfg( feature = "alloc" ) ]
12
13
use super :: CString16 ;
@@ -24,6 +25,19 @@ pub enum FromSliceWithNulError {
24
25
NotNulTerminated ,
25
26
}
26
27
28
+ impl Display for FromSliceWithNulError {
29
+ fn fmt ( & self , f : & mut Formatter < ' _ > ) -> fmt:: Result {
30
+ match self {
31
+ Self :: InvalidChar ( usize) => write ! ( f, "invalid character at index {}" , usize ) ,
32
+ Self :: InteriorNul ( usize) => write ! ( f, "interior null character at index {}" , usize ) ,
33
+ Self :: NotNulTerminated => write ! ( f, "not null-terminated" ) ,
34
+ }
35
+ }
36
+ }
37
+
38
+ #[ cfg( feature = "unstable" ) ]
39
+ impl core:: error:: Error for FromSliceWithNulError { }
40
+
27
41
/// Error returned by [`CStr16::from_unaligned_slice`].
28
42
#[ derive( Clone , Copy , Debug , Eq , PartialEq ) ]
29
43
pub enum UnalignedCStr16Error {
@@ -41,6 +55,20 @@ pub enum UnalignedCStr16Error {
41
55
BufferTooSmall ,
42
56
}
43
57
58
+ impl Display for UnalignedCStr16Error {
59
+ fn fmt ( & self , f : & mut Formatter < ' _ > ) -> fmt:: Result {
60
+ match self {
61
+ Self :: InvalidChar ( usize) => write ! ( f, "invalid character at index {}" , usize ) ,
62
+ Self :: InteriorNul ( usize) => write ! ( f, "interior null character at index {}" , usize ) ,
63
+ Self :: NotNulTerminated => write ! ( f, "not null-terminated" ) ,
64
+ Self :: BufferTooSmall => write ! ( f, "buffer too small" ) ,
65
+ }
66
+ }
67
+ }
68
+
69
+ #[ cfg( feature = "unstable" ) ]
70
+ impl core:: error:: Error for UnalignedCStr16Error { }
71
+
44
72
/// Error returned by [`CStr16::from_str_with_buf`].
45
73
#[ derive( Clone , Copy , Debug , Eq , PartialEq ) ]
46
74
pub enum FromStrWithBufError {
@@ -55,6 +83,19 @@ pub enum FromStrWithBufError {
55
83
BufferTooSmall ,
56
84
}
57
85
86
+ impl Display for FromStrWithBufError {
87
+ fn fmt ( & self , f : & mut Formatter < ' _ > ) -> fmt:: Result {
88
+ match self {
89
+ Self :: InvalidChar ( usize) => write ! ( f, "invalid character at index {}" , usize ) ,
90
+ Self :: InteriorNul ( usize) => write ! ( f, "interior null character at index {}" , usize ) ,
91
+ Self :: BufferTooSmall => write ! ( f, "buffer too small" ) ,
92
+ }
93
+ }
94
+ }
95
+
96
+ #[ cfg( feature = "unstable" ) ]
97
+ impl core:: error:: Error for FromStrWithBufError { }
98
+
58
99
/// A null-terminated Latin-1 string.
59
100
///
60
101
/// This type is largely inspired by [`core::ffi::CStr`] with the exception that all characters are
0 commit comments