naga::common::wgsl::to_wgsl

Trait TryToWgsl

Source
pub trait TryToWgsl: Sized {
    const DESCRIPTION: &'static str;

    // Required method
    fn try_to_wgsl(self) -> Option<&'static str>;

    // Provided method
    fn to_wgsl_for_diagnostics(self) -> String
       where Self: Debug + Copy { ... }
}
Expand description

Types that may be able to return the WGSL source representation for their values as a 'static string.

This trait is specifically for types whose values are either simple enough that their WGSL form can be represented a static string, or aren’t representable in WGSL at all.

  • If all values in the type have &'static str representations in WGSL, consider implementing ToWgsl instead.

  • If a type’s WGSL form requires dynamic formatting, so that returning a &'static str isn’t feasible, consider implementing std::fmt::Display on some wrapper type instead.

Required Associated Constants§

Source

const DESCRIPTION: &'static str

What kind of WGSL thing Self represents.

Required Methods§

Source

fn try_to_wgsl(self) -> Option<&'static str>

Return the WGSL form of self as a 'static string.

If self doesn’t have a representation in WGSL (standard or as extended by Naga), then return None.

Provided Methods§

Source

fn to_wgsl_for_diagnostics(self) -> String
where Self: Debug + Copy,

Return the WGSL form of self as appropriate for diagnostics.

If self can be expressed in WGSL, return that form as a String. Otherwise, return some representation of self that is appropriate for use in diagnostic messages.

The default implementation of this function falls back to self’s Debug form.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl TryToWgsl for BuiltIn

Source§

const DESCRIPTION: &'static str = "builtin value"

Source§

impl TryToWgsl for MathFunction

Source§

const DESCRIPTION: &'static str = "math function"

Source§

impl TryToWgsl for Scalar

Source§

const DESCRIPTION: &'static str = "scalar type"