pub trait Mangler {
// Required method
fn mangle(&self, path: &ModulePath, item: &str) -> String;
// Provided methods
fn unmangle(&self, _mangled: &str) -> Option<(ModulePath, String)> { ... }
fn mangle_types(
&self,
item: &str,
variant: u32,
_types: &[TypeExpression],
) -> String { ... }
}Expand description
A name mangler is responsible for renaming import-qualified identifiers into valid WGSL identifiers.
Mangler implementations must respect the following constraints:
- A pair {path, item} (aka. fully-qualified name) must be associated with a unique mangled name.
- A mangled name must be associated with a unique pair {path, item} (or at least, the risk of a collision must be negligible).
- The mangled name must be a valid WGSL identifier.
Calls to Mangler::mangle must respect these preconditions:
- the item must be a valid WGSL identifier.
§WESL Reference
spec: NameMangling.md
Required Methods§
Sourcefn mangle(&self, path: &ModulePath, item: &str) -> String
fn mangle(&self, path: &ModulePath, item: &str) -> String
Turn an import path and item name into a mangled WGSL identifier.
Provided Methods§
Sourcefn unmangle(&self, _mangled: &str) -> Option<(ModulePath, String)>
fn unmangle(&self, _mangled: &str) -> Option<(ModulePath, String)>
Reverse the Mangler::mangle operation. Implementing this is optional.
Sourcefn mangle_types(
&self,
item: &str,
variant: u32,
_types: &[TypeExpression],
) -> String
fn mangle_types( &self, item: &str, variant: u32, _types: &[TypeExpression], ) -> String
Used for generics. Is experimental. Implementing is optional.
Trait Implementations§
Source§impl From<ManglerKind> for Box<dyn Mangler>
impl From<ManglerKind> for Box<dyn Mangler>
Source§fn from(kind: ManglerKind) -> Self
fn from(kind: ManglerKind) -> Self
Converts to this type from the input type.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".