@@ -17,6 +17,8 @@ pub struct MetadataCache {
1717}
1818
1919impl MetadataCache {
20+ /// Return the cached cargo metadata for the Cargo.toml at the given path,
21+ /// or find it, populate the cache with it and return it.
2022 fn get_metadata (
2123 & mut self ,
2224 maybe_path_to_manifest_dir : Option < & std:: path:: Path > ,
@@ -32,11 +34,15 @@ impl MetadataCache {
3234 self . inner . insert ( path. clone ( ) , metadata) ;
3335 }
3436
35- // UNWRAP: safe because we just inserted it
36- Ok ( self . inner . get ( & path) . unwrap ( ) )
37+ self . inner . get ( & path) . context ( "unreachable" )
3738 }
3839
3940 /// Resolve a package name to a crate directory.
41+ ///
42+ /// ## Errors
43+ /// * if fetching cargo metadata fails.
44+ /// * if no packages are listed in the cargo metadata.
45+ /// * if the manifest path has no parent.
4046 pub fn resolve_package_to_shader_crate (
4147 & mut self ,
4248 package : & str ,
@@ -69,7 +75,10 @@ impl MetadataCache {
6975 /// First we generate the CLI arg defaults as JSON. Then on top of those we merge any config
7076 /// from the workspace `Cargo.toml`, then on top of those we merge any config from the shader
7177 /// crate's `Cargo.toml`.
72- pub fn as_json ( & mut self , path : & std:: path:: PathBuf ) -> anyhow:: Result < Value > {
78+ ///
79+ /// ## Errors
80+ /// Errors if cargo metadata cannot be found or if it cannot be operated on.
81+ pub fn as_json ( & mut self , path : & std:: path:: Path ) -> anyhow:: Result < Value > {
7382 log:: debug!( "reading package metadata from {}" , path. display( ) ) ;
7483 let cargo_json = self . get_cargo_toml_as_json ( path) ?;
7584 let config = Self :: merge_configs ( & cargo_json, path) ?;
@@ -121,9 +130,9 @@ impl MetadataCache {
121130 /// Convert a `Cargo.toml` to JSON
122131 fn get_cargo_toml_as_json (
123132 & mut self ,
124- path : & std:: path:: PathBuf ,
133+ path : & std:: path:: Path ,
125134 ) -> anyhow:: Result < cargo_metadata:: Metadata > {
126- self . get_metadata ( Some ( path. as_path ( ) ) ) . cloned ( )
135+ self . get_metadata ( Some ( path) ) . cloned ( )
127136 }
128137
129138 /// Get any `rust-gpu` metadata set in the crate's `Cargo.toml`
0 commit comments