@@ -26,6 +26,7 @@ struct CargoPackage {
26
26
27
27
#[ derive( Deserialize ) ]
28
28
struct CargoLib {
29
+ #[ serde( rename = "crate-type" ) ]
29
30
crate_type : Option < Vec < String > > ,
30
31
}
31
32
@@ -55,9 +56,7 @@ fn read_cargo_toml(path: &str) -> Result<CargoManifest, Error> {
55
56
let mut cargo_contents = String :: new ( ) ;
56
57
cargo_file. read_to_string ( & mut cargo_contents) ?;
57
58
58
- Ok ( toml:: from_str (
59
- & cargo_contents. replace ( "crate-type" , "crate_type" ) ,
60
- ) ?)
59
+ Ok ( toml:: from_str ( & cargo_contents) ?)
61
60
}
62
61
63
62
impl CargoManifest {
@@ -145,18 +144,15 @@ pub fn get_crate_name(path: &str) -> Result<String, Error> {
145
144
Ok ( read_cargo_toml ( path) ?. package . name )
146
145
}
147
146
148
- fn has_cdylib ( path : & str ) -> bool {
149
- match read_cargo_toml ( path) . unwrap ( ) . lib {
150
- Some ( lib) => match lib. crate_type {
151
- Some ( types) => types. iter ( ) . any ( |s| s == "cdylib" ) ,
152
- _ => false ,
153
- } ,
154
- _ => false ,
155
- }
147
+ fn has_cdylib ( path : & str ) -> Result < bool , Error > {
148
+ Ok ( read_cargo_toml ( path) ?. lib . map_or ( false , |lib| {
149
+ lib. crate_type
150
+ . map_or ( false , |types| types. iter ( ) . any ( |s| s == "cdylib" ) )
151
+ } ) )
156
152
}
157
153
158
154
pub fn check_crate_type ( path : & str ) -> Result < ( ) , Error > {
159
- if !has_cdylib ( path) {
155
+ if !has_cdylib ( path) ? {
160
156
Error :: config ( "crate-type must include cdylib to compile to wasm32-unknown-unknown" )
161
157
} else {
162
158
Ok ( ( ) )
0 commit comments