@@ -11,9 +11,10 @@ use core::str::Utf8Error;
11
11
/// Error type describing failures when parsing the string from a tag.
12
12
#[ derive( Debug , PartialEq , Eq , Clone ) ]
13
13
pub enum StringError {
14
- /// There is no terminating null-byte, although the spec requires one.
15
- MissingNull ( core:: ffi:: FromBytesUntilNulError ) ,
16
- /// The sequence until the first NULL byte is not valid UTF-8.
14
+ /// There is no terminating NUL character, although the specification
15
+ /// requires one.
16
+ MissingNul ( core:: ffi:: FromBytesUntilNulError ) ,
17
+ /// The sequence until the first NUL character is not valid UTF-8.
17
18
Utf8 ( Utf8Error ) ,
18
19
}
19
20
@@ -27,7 +28,7 @@ impl Display for StringError {
27
28
impl core:: error:: Error for StringError {
28
29
fn source ( & self ) -> Option < & ( dyn core:: error:: Error + ' static ) > {
29
30
match self {
30
- StringError :: MissingNull ( e) => Some ( e) ,
31
+ StringError :: MissingNul ( e) => Some ( e) ,
31
32
StringError :: Utf8 ( e) => Some ( e) ,
32
33
}
33
34
}
@@ -66,8 +67,7 @@ impl Tag {
66
67
/// Parses the provided byte sequence as Multiboot string, which maps to a
67
68
/// [`str`].
68
69
pub fn parse_slice_as_string ( bytes : & [ u8 ] ) -> Result < & str , StringError > {
69
- let cstr =
70
- core:: ffi:: CStr :: from_bytes_until_nul ( bytes) . map_err ( StringError :: MissingNull ) ?;
70
+ let cstr = core:: ffi:: CStr :: from_bytes_until_nul ( bytes) . map_err ( StringError :: MissingNul ) ?;
71
71
72
72
cstr. to_str ( ) . map_err ( StringError :: Utf8 )
73
73
}
@@ -148,7 +148,7 @@ mod tests {
148
148
// empty slice is invalid
149
149
assert ! ( matches!(
150
150
Tag :: parse_slice_as_string( & [ ] ) ,
151
- Err ( StringError :: MissingNull ( _) )
151
+ Err ( StringError :: MissingNul ( _) )
152
152
) ) ;
153
153
// empty string is fine
154
154
assert_eq ! ( Tag :: parse_slice_as_string( & [ 0x00 ] ) , Ok ( "" ) ) ;
@@ -160,7 +160,7 @@ mod tests {
160
160
// reject missing null
161
161
assert ! ( matches!(
162
162
Tag :: parse_slice_as_string( b"hello" ) ,
163
- Err ( StringError :: MissingNull ( _) )
163
+ Err ( StringError :: MissingNul ( _) )
164
164
) ) ;
165
165
// must not include final null
166
166
assert_eq ! ( Tag :: parse_slice_as_string( b"hello\0 " ) , Ok ( "hello" ) ) ;
0 commit comments