Skip to main content

Mangler

Trait Mangler 

Source
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§

Source

fn mangle(&self, path: &ModulePath, item: &str) -> String

Turn an import path and item name into a mangled WGSL identifier.

Provided Methods§

Source

fn unmangle(&self, _mangled: &str) -> Option<(ModulePath, String)>

Reverse the Mangler::mangle operation. Implementing this is optional.

Source

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>

Source§

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".

Implementations on Foreign Types§

Source§

impl<T: Mangler + ?Sized> Mangler for &T

Source§

fn mangle(&self, path: &ModulePath, item: &str) -> String

Source§

fn unmangle(&self, mangled: &str) -> Option<(ModulePath, String)>

Source§

fn mangle_types( &self, item: &str, variant: u32, types: &[TypeExpression], ) -> String

Source§

impl<T: Mangler + ?Sized> Mangler for Box<T>

Source§

fn mangle(&self, path: &ModulePath, item: &str) -> String

Source§

fn unmangle(&self, mangled: &str) -> Option<(ModulePath, String)>

Source§

fn mangle_types( &self, item: &str, variant: u32, types: &[TypeExpression], ) -> String

Implementors§