#![no_std]
extern crate alloc;
use alloc::string::String;
use core::fmt;
use naga::valid::Capabilities;
mod config;
mod conv;
mod util;
mod writer;
pub use config::Config;
pub use writer::Writer;
pub use naga;
pub const CAPABILITIES: Capabilities = Capabilities::FLOAT64;
#[derive(Debug)]
#[non_exhaustive]
pub enum Error {
FmtError(fmt::Error),
Unimplemented(String),
#[non_exhaustive]
TexturesAreUnsupported {
found: &'static str,
},
#[non_exhaustive]
GlobalVariablesNotEnabled {
example: String,
},
}
impl From<fmt::Error> for Error {
fn from(value: fmt::Error) -> Self {
Self::FmtError(value)
}
}
impl core::error::Error for Error {}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Error::FmtError(fmt::Error) => write!(f, "formatting cancelled"),
Error::Unimplemented(msg) => write!(f, "not yet implemented for Rust: {msg}"),
Error::TexturesAreUnsupported { found } => {
write!(f, "texture operations, such as {found}, are not supported")
}
Error::GlobalVariablesNotEnabled { example } => write!(
f,
"global variable `{example}` found in shader, but not enabled in Config"
),
}
}
}
pub fn write_string(
module: &naga::Module,
info: &naga::valid::ModuleInfo,
config: Config,
) -> Result<String, Error> {
let mut w = Writer::new(config);
let mut output = String::new();
w.write(&mut output, module, info)?;
Ok(output)
}