use alloc::borrow::Cow;
use alloc::string::String;
#[derive(Debug)]
pub struct Config {
pub(crate) flags: WriterFlags,
pub(crate) runtime_path: Cow<'static, str>,
pub(crate) global_struct: Option<String>,
#[allow(dead_code, reason = "reminding ourselves of the future")]
pub(crate) edition: Edition,
}
impl Default for Config {
fn default() -> Self {
Self::new()
}
}
impl Config {
#[must_use]
pub const fn new() -> Self {
Self {
flags: WriterFlags::empty(),
runtime_path: Cow::Borrowed("::naga_rust_rt"),
global_struct: None,
edition: Edition::Rust2024,
}
}
#[must_use]
pub fn explicit_types(mut self, value: bool) -> Self {
self.flags.set(WriterFlags::EXPLICIT_TYPES, value);
self
}
#[must_use]
pub fn raw_pointers(mut self, value: bool) -> Self {
self.flags.set(WriterFlags::RAW_POINTERS, value);
self
}
#[must_use]
pub fn public_items(mut self, value: bool) -> Self {
self.flags.set(WriterFlags::PUBLIC, value);
self
}
#[must_use]
pub fn runtime_path(mut self, value: impl Into<Cow<'static, str>>) -> Self {
let value = value.into();
assert!(
value.starts_with("::") || value.starts_with("crate::"),
"path should be an absolute path"
);
self.runtime_path = value;
self
}
#[must_use]
pub fn global_struct(mut self, name: impl Into<String>) -> Self {
self.global_struct = Some(name.into());
self
}
pub(crate) fn use_global_struct(&self) -> bool {
self.global_struct.is_some()
}
}
bitflags::bitflags! {
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub(crate) struct WriterFlags: u32 {
const EXPLICIT_TYPES = 0x1;
const RAW_POINTERS = 0x2;
const PUBLIC = 0x3;
}
}
#[derive(Clone, Copy, Debug)]
pub(crate) enum Edition {
Rust2024,
}