@@ -26,6 +26,7 @@ struct CargoPackage {
2626
2727#[ derive( Deserialize ) ]
2828struct CargoLib {
29+ #[ serde( rename = "crate-type" ) ]
2930 crate_type : Option < Vec < String > > ,
3031}
3132
@@ -55,9 +56,7 @@ fn read_cargo_toml(path: &str) -> Result<CargoManifest, Error> {
5556 let mut cargo_contents = String :: new ( ) ;
5657 cargo_file. read_to_string ( & mut cargo_contents) ?;
5758
58- Ok ( toml:: from_str (
59- & cargo_contents. replace ( "crate-type" , "crate_type" ) ,
60- ) ?)
59+ Ok ( toml:: from_str ( & cargo_contents) ?)
6160}
6261
6362impl CargoManifest {
@@ -145,18 +144,15 @@ pub fn get_crate_name(path: &str) -> Result<String, Error> {
145144 Ok ( read_cargo_toml ( path) ?. package . name )
146145}
147146
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+ } ) )
156152}
157153
158154pub fn check_crate_type ( path : & str ) -> Result < ( ) , Error > {
159- if !has_cdylib ( path) {
155+ if !has_cdylib ( path) ? {
160156 Error :: config ( "crate-type must include cdylib to compile to wasm32-unknown-unknown" )
161157 } else {
162158 Ok ( ( ) )
0 commit comments