File tree Expand file tree Collapse file tree 1 file changed +5
-4
lines changed Expand file tree Collapse file tree 1 file changed +5
-4
lines changed Original file line number Diff line number Diff line change
1
+ use std:: mem:: MaybeUninit ;
1
2
use std:: { ptr, str, slice, fmt } ;
2
3
use std:: ops:: Deref ;
3
4
@@ -6,7 +7,7 @@ pub const MAX_LEN: usize = 30;
6
7
#[ derive( Clone , Copy ) ]
7
8
pub struct Short {
8
9
len : u8 ,
9
- value : [ u8 ; MAX_LEN ] ,
10
+ value : [ MaybeUninit < u8 > ; MAX_LEN ] ,
10
11
}
11
12
12
13
/// A `Short` is a small string, up to `MAX_LEN` bytes, that can be managed without
@@ -23,11 +24,11 @@ impl Short {
23
24
#[ inline( always) ]
24
25
pub unsafe fn from_slice ( slice : & str ) -> Self {
25
26
let mut short = Short {
26
- value : [ 0 ; MAX_LEN ] ,
27
+ value : MaybeUninit :: uninit ( ) . assume_init ( ) ,
27
28
len : slice. len ( ) as u8 ,
28
29
} ;
29
30
30
- ptr:: copy_nonoverlapping ( slice. as_ptr ( ) , short. value . as_mut_ptr ( ) , slice. len ( ) ) ;
31
+ ptr:: copy_nonoverlapping ( slice. as_ptr ( ) , short. value . as_mut_ptr ( ) as _ , slice. len ( ) ) ;
31
32
32
33
short
33
34
}
@@ -37,7 +38,7 @@ impl Short {
37
38
pub fn as_str ( & self ) -> & str {
38
39
unsafe {
39
40
str:: from_utf8_unchecked (
40
- slice:: from_raw_parts ( self . value . as_ptr ( ) , self . len as usize )
41
+ slice:: from_raw_parts ( self . value . as_ptr ( ) as _ , self . len as usize )
41
42
)
42
43
}
43
44
}
You can’t perform that action at this time.
0 commit comments