Backed out 5 changesets (bug 1890092, bug 1888683) for causing build bustages & crash...
[gecko.git] / third_party / rust / uniffi_bindgen / src / bindings / python / templates / CustomType.py
blob5be6155b84996c4ff1dfbc364ac5a9e569c2b07a
1 {%- match python_config.custom_types.get(name.as_str()) %}
2 {% when None %}
3 {#- No custom type config, just forward all methods to our builtin type #}
4 # Type alias
5 {{ name }} = {{ builtin|type_name }}
7 class _UniffiConverterType{{ name }}:
8 @staticmethod
9 def write(value, buf):
10 {{ builtin|ffi_converter_name }}.write(value, buf)
12 @staticmethod
13 def read(buf):
14 return {{ builtin|ffi_converter_name }}.read(buf)
16 @staticmethod
17 def lift(value):
18 return {{ builtin|ffi_converter_name }}.lift(value)
20 @staticmethod
21 def lower(value):
22 return {{ builtin|ffi_converter_name }}.lower(value)
24 {%- when Some(config) %}
26 {%- match config.imports %}
27 {%- when Some(imports) %}
28 {%- for import_name in imports %}
29 {{ self.add_import(import_name) }}
30 {%- endfor %}
31 {%- else %}
32 {%- endmatch %}
34 # Type alias
35 {{ name }} = {{ builtin|type_name }}
37 {#- Custom type config supplied, use it to convert the builtin type #}
38 class _UniffiConverterType{{ name }}:
39 @staticmethod
40 def write(value, buf):
41 builtin_value = {{ config.from_custom.render("value") }}
42 {{ builtin|write_fn }}(builtin_value, buf)
44 @staticmethod
45 def read(buf):
46 builtin_value = {{ builtin|read_fn }}(buf)
47 return {{ config.into_custom.render("builtin_value") }}
49 @staticmethod
50 def lift(value):
51 builtin_value = {{ builtin|lift_fn }}(value)
52 return {{ config.into_custom.render("builtin_value") }}
54 @staticmethod
55 def lower(value):
56 builtin_value = {{ config.from_custom.render("value") }}
57 return {{ builtin|lower_fn }}(builtin_value)
58 {%- endmatch %}