Skip to content

Commit d070b86

Browse files
committed
add generic variants of CompileResult and ModuleResult
1 parent 86fc480 commit d070b86

File tree

2 files changed

+19
-19
lines changed

2 files changed

+19
-19
lines changed

crates/rustc_codegen_spirv-types/src/compile_result.rs

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,46 @@
11
use serde::{Deserialize, Serialize};
22
use std::collections::BTreeMap;
33
use std::fmt::Write;
4-
use std::path::{Path, PathBuf};
4+
use std::path::PathBuf;
5+
6+
pub type ModuleResult = GenericModuleResult<PathBuf>;
57

68
#[derive(Debug, Serialize, Deserialize)]
79
#[serde(untagged)]
8-
pub enum ModuleResult {
9-
SingleModule(PathBuf),
10-
MultiModule(BTreeMap<String, PathBuf>),
10+
pub enum GenericModuleResult<T> {
11+
SingleModule(T),
12+
MultiModule(BTreeMap<String, T>),
1113
}
1214

13-
impl ModuleResult {
14-
pub fn unwrap_single(&self) -> &Path {
15+
impl<T> GenericModuleResult<T> {
16+
pub fn unwrap_single(&self) -> &T {
1517
match self {
16-
ModuleResult::SingleModule(result) => result,
17-
ModuleResult::MultiModule(_) => {
18+
GenericModuleResult::SingleModule(result) => result,
19+
GenericModuleResult::MultiModule(_) => {
1820
panic!("called `ModuleResult::unwrap_single()` on a `MultiModule` result")
1921
}
2022
}
2123
}
2224

23-
pub fn unwrap_multi(&self) -> &BTreeMap<String, PathBuf> {
25+
pub fn unwrap_multi(&self) -> &BTreeMap<String, T> {
2426
match self {
25-
ModuleResult::MultiModule(result) => result,
26-
ModuleResult::SingleModule(_) => {
27+
GenericModuleResult::MultiModule(result) => result,
28+
GenericModuleResult::SingleModule(_) => {
2729
panic!("called `ModuleResult::unwrap_multi()` on a `SingleModule` result")
2830
}
2931
}
3032
}
3133
}
3234

35+
pub type CompileResult = GenericCompileResult<PathBuf>;
36+
3337
#[derive(Debug, Serialize, Deserialize)]
34-
pub struct CompileResult {
38+
pub struct GenericCompileResult<T> {
3539
pub entry_points: Vec<String>,
36-
pub module: ModuleResult,
40+
pub module: GenericModuleResult<T>,
3741
}
3842

39-
impl CompileResult {
43+
impl<T> GenericCompileResult<T> {
4044
pub fn codegen_entry_point_strings(&self) -> String {
4145
let trie = Trie::create_from(self.entry_points.iter().map(|x| x as &str));
4246
let mut builder = String::new();
@@ -110,9 +114,6 @@ impl<'a> Trie<'a> {
110114
}
111115
}
112116

113-
#[allow(non_upper_case_globals)]
114-
pub const a: &str = "x::a";
115-
116117
#[cfg(test)]
117118
mod test {
118119
use super::*;

crates/spirv-builder/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,7 @@ use std::path::{Path, PathBuf};
8888
use std::process::{Command, Stdio};
8989
use thiserror::Error;
9090

91-
pub use rustc_codegen_spirv_types::Capability;
92-
pub use rustc_codegen_spirv_types::{CompileResult, ModuleResult};
91+
pub use rustc_codegen_spirv_types::*;
9392

9493
#[cfg(feature = "include-target-specs")]
9594
pub use rustc_codegen_spirv_target_specs::TARGET_SPEC_DIR_PATH;

0 commit comments

Comments
 (0)