Skip to main content

TypeMapper

Trait TypeMapper 

Source
pub trait TypeMapper {
Show 14 methods // Required method fn error_wrapper(&self) -> &str; // Provided methods fn primitive(&self, prim: &PrimitiveType) -> Cow<'static, str> { ... } fn string(&self) -> Cow<'static, str> { ... } fn bytes(&self) -> Cow<'static, str> { ... } fn path(&self) -> Cow<'static, str> { ... } fn json(&self) -> Cow<'static, str> { ... } fn unit(&self) -> Cow<'static, str> { ... } fn duration(&self) -> Cow<'static, str> { ... } fn optional(&self, inner: &str) -> String { ... } fn vec(&self, inner: &str) -> String { ... } fn map(&self, key: &str, value: &str) -> String { ... } fn named<'a>(&self, name: &'a str) -> Cow<'a, str> { ... } fn map_type(&self, ty: &TypeRef) -> String { ... } fn wrap_return(&self, base: &str, has_error: bool) -> String { ... }
}
Expand description

Trait for mapping IR types to language-specific type strings. Backends implement only what differs from the Rust default.

Required Methods§

Source

fn error_wrapper(&self) -> &str

The error wrapper type for this language. e.g. “PyResult”, “napi::Result”, “PhpResult”

Provided Methods§

Source

fn primitive(&self, prim: &PrimitiveType) -> Cow<'static, str>

Map a primitive type. Default: Rust type names.

Source

fn string(&self) -> Cow<'static, str>

Map a string type. Default: “String”

Source

fn bytes(&self) -> Cow<'static, str>

Map a bytes type. Default: “Vec

Source

fn path(&self) -> Cow<'static, str>

Map a path type. Default: “String”

Source

fn json(&self) -> Cow<'static, str>

Map a JSON type. Default: “serde_json::Value”

Source

fn unit(&self) -> Cow<'static, str>

Map a unit type. Default: “()”

Source

fn duration(&self) -> Cow<'static, str>

Map a duration type. Default: “u64” (seconds)

Source

fn optional(&self, inner: &str) -> String

Map an optional type. Default: “Option

Source

fn vec(&self, inner: &str) -> String

Map a vec type. Default: “Vec

Source

fn map(&self, key: &str, value: &str) -> String

Map a map type. Default: “HashMap<K, V>”

Source

fn named<'a>(&self, name: &'a str) -> Cow<'a, str>

Map a named type. Default: identity.

Source

fn map_type(&self, ty: &TypeRef) -> String

Map a full TypeRef. Typically not overridden.

Source

fn wrap_return(&self, base: &str, has_error: bool) -> String

Wrap a return type with error handling if needed.

Implementors§