@@ -22,6 +22,7 @@ use std::path::{Path, PathBuf};
2222/// - a repo of "https://github.com/Rust-GPU/rust-gpu.git"
2323/// - a revision of "abc213"
2424/// * a local Path
25+ #[ non_exhaustive]
2526#[ derive( Eq , PartialEq , Clone , Debug ) ]
2627pub enum SpirvSource {
2728 /// If the shader specifies a simple version like `spirv-std = "0.9.0"` then the source of
@@ -69,6 +70,9 @@ impl core::fmt::Display for SpirvSource {
6970
7071impl SpirvSource {
7172 /// Figures out which source of `rust-gpu` to use
73+ ///
74+ /// # Errors
75+ /// Crate may not depend on `spirv-std` or is otherwise malformed
7276 pub fn new (
7377 shader_crate_path : & Path ,
7478 maybe_rust_gpu_source : Option < & str > ,
@@ -95,6 +99,9 @@ impl SpirvSource {
9599 }
96100
97101 /// Look into the shader crate to get the version of `rust-gpu` it's using.
102+ ///
103+ /// # Errors
104+ /// Crate may not depend on `spirv-std` or is otherwise malformed
98105 pub fn get_rust_gpu_deps_from_shader ( shader_crate_path : & Path ) -> anyhow:: Result < Self > {
99106 let crate_metadata = query_metadata ( shader_crate_path) ?;
100107 let spirv_std_package = crate_metadata. find_package ( "spirv-std" ) ?;
@@ -110,6 +117,9 @@ impl SpirvSource {
110117 /// Convert the `SpirvSource` to a cache directory in which we can build it.
111118 /// It needs to be dynamically created because an end-user might want to swap out the source,
112119 /// maybe using their own fork for example.
120+ ///
121+ /// # Errors
122+ /// [`crate::cache_dir`] may fail
113123 pub fn install_dir ( & self ) -> anyhow:: Result < PathBuf > {
114124 match self {
115125 Self :: Path {
@@ -123,6 +133,7 @@ impl SpirvSource {
123133 }
124134
125135 /// Returns true if self is a Path
136+ #[ must_use]
126137 pub const fn is_path ( & self ) -> bool {
127138 matches ! ( self , Self :: Path { .. } )
128139 }
@@ -182,6 +193,9 @@ impl SpirvSource {
182193}
183194
184195/// get the Package metadata from some crate
196+ ///
197+ /// # Errors
198+ /// metadata query may fail
185199pub fn query_metadata ( crate_path : & Path ) -> anyhow:: Result < Metadata > {
186200 log:: debug!( "Running `cargo metadata` on `{}`" , crate_path. display( ) ) ;
187201 let metadata = MetadataCommand :: new ( )
@@ -197,6 +211,9 @@ pub fn query_metadata(crate_path: &Path) -> anyhow::Result<Metadata> {
197211/// implements [`Self::find_package`]
198212pub trait FindPackage {
199213 /// Search for a package or return a nice error
214+ ///
215+ /// # Errors
216+ /// package may not be found or crate may be malformed
200217 fn find_package ( & self , crate_name : & str ) -> anyhow:: Result < & Package > ;
201218}
202219
@@ -219,6 +236,9 @@ impl FindPackage for Metadata {
219236}
220237
221238/// Parse the `rust-toolchain.toml` in the working tree of the checked-out version of the `rust-gpu` repo.
239+ ///
240+ /// # Errors
241+ /// parsing may fail
222242pub fn get_channel_from_rustc_codegen_spirv_build_script (
223243 rustc_codegen_spirv_package : & Package ,
224244) -> anyhow:: Result < String > {
0 commit comments