File tree Expand file tree Collapse file tree 2 files changed +27
-2
lines changed
Expand file tree Collapse file tree 2 files changed +27
-2
lines changed Original file line number Diff line number Diff line change 11use binrw:: { binrw, NullString } ;
2+ use binrw:: binrw;
3+
4+ use crate :: utils:: { nullstr_read, nullstr_write} ;
25
36#[ binrw]
47#[ brw( little) ]
58#[ derive( Debug , PartialEq , Default ) ]
9+ #[ cfg_attr( test, derive( proptest_derive:: Arbitrary ) ) ]
610pub enum ModpkgLicense {
711 #[ default]
812 #[ brw( magic = 0u8 ) ]
913 None ,
1014 #[ brw( magic = 1u8 ) ]
11- Spdx { spdx_id : NullString } ,
15+ Spdx {
16+ #[ bw( map = nullstr_write) ]
17+ #[ br( try_map = nullstr_read) ]
18+ spdx_id : String ,
19+ } ,
1220 #[ brw( magic = 2u8 ) ]
13- Custom { name : NullString , url : NullString } ,
21+ Custom {
22+ #[ bw( map = nullstr_write) ]
23+ #[ br( try_map = nullstr_read) ]
24+ name : String ,
25+ #[ bw( map = nullstr_write) ]
26+ #[ br( try_map = nullstr_read) ]
27+ url : String ,
28+ } ,
1429}
1530
1631impl ModpkgLicense {
Original file line number Diff line number Diff line change 1+ use binrw:: NullString ;
2+
13pub fn optional_string_len < ' a > ( string : impl Into < Option < & ' a String > > ) -> usize {
24 string. into ( ) . as_ref ( ) . map ( |n| n. len ( ) ) . unwrap_or_default ( )
35}
@@ -8,3 +10,11 @@ pub fn optional_string_write(s: &Option<String>) -> Option<Vec<u8>> {
810pub fn optional_string_read ( s : Vec < u8 > ) -> Result < Option < String > , std:: string:: FromUtf8Error > {
911 String :: from_utf8 ( s) . map ( Some )
1012}
13+
14+ pub fn nullstr_read ( s : NullString ) -> Result < String , std:: string:: FromUtf8Error > {
15+ String :: from_utf8 ( s. into ( ) )
16+ }
17+
18+ pub fn nullstr_write < ' a > ( s : impl Into < & ' a String > ) -> NullString {
19+ NullString :: from ( s. into ( ) . as_str ( ) )
20+ }
You can’t perform that action at this time.
0 commit comments