Debian Codegraph @

third_party/rust/uniffi_bindgen/src/bindings/ruby/templates/macros.rb

raw
1 {#
2 // Template to call into rust. Used in several places.
3 // Variable names in `arg_list_decl` should match up with arg lists
4 // passed to rust via `_arg_list_ffi_call` (we use `var_name_rb` in `lower_rb`)
5 #}
6
7 {%- macro to_ffi_call(func) -%}
8 {%- match func.throws_name() -%}
9 {%- when Some with (e) -%}
10 {{ ci.namespace()|class_name_rb }}.rust_call_with_error({{ e|class_name_rb }},
11 {%- else -%}
12 {{ ci.namespace()|class_name_rb }}.rust_call(
13 {%- endmatch -%}
14 :{{ func.ffi_func().name() }},
15 {%- call _arg_list_ffi_call(func) -%}
16 )
17 {%- endmacro -%}
18
19 {%- macro to_ffi_call_with_prefix(prefix, func) -%}
20 {%- match func.throws_name() -%}
21 {%- when Some with (e) -%}
22 {{ ci.namespace()|class_name_rb }}.rust_call_with_error({{ e|class_name_rb }},
23 {%- else -%}
24 {{ ci.namespace()|class_name_rb }}.rust_call(
25 {%- endmatch -%}
26 :{{ func.ffi_func().name() }},
27 {{- prefix }},
28 {%- call _arg_list_ffi_call(func) -%}
29 )
30 {%- endmacro -%}
31
32 {%- macro _arg_list_ffi_call(func) %}
33 {%- for arg in func.arguments() %}
34 {{- arg.name()|lower_rb(arg.as_type().borrow()) }}
35 {%- if !loop.last %},{% endif %}
36 {%- endfor %}
37 {%- endmacro -%}
38
39 {#-
40 // Arglist as used in Ruby declarations of methods, functions and constructors.
41 // Note the var_name_rb and type_rb filters.
42 -#}
43
44 {% macro arg_list_decl(func) %}
45 {%- for arg in func.arguments() -%}
46 {{ arg.name()|var_name_rb }}
47 {%- match arg.default_value() %}
48 {%- when Some with(literal) %} = {{ literal|literal_rb }}
49 {%- else %}
50 {%- endmatch %}
51 {%- if !loop.last %}, {% endif -%}
52 {%- endfor %}
53 {%- endmacro %}
54
55 {#-
56 // Arglist as used in the UniFFILib function declarations.
57 // Note unfiltered name but type_ffi filters.
58 -#}
59 {%- macro arg_list_ffi_decl(func) %}
60 [{%- for arg in func.arguments() -%}{{ arg.type_().borrow()|type_ffi }}, {% endfor -%} RustCallStatus.by_ref]
61 {%- endmacro -%}
62
63 {%- macro setup_args(func) %}
64 {%- for arg in func.arguments() %}
65 {{ arg.name() }} = {{ arg.name()|coerce_rb(ci.namespace()|class_name_rb, arg.as_type().borrow()) }}
66 {{ arg.name()|check_lower_rb(arg.as_type().borrow()) }}
67 {% endfor -%}
68 {%- endmacro -%}
69
70 {%- macro setup_args_extra_indent(meth) %}
71 {%- for arg in meth.arguments() %}
72 {{ arg.name() }} = {{ arg.name()|coerce_rb(ci.namespace()|class_name_rb, arg.as_type().borrow()) }}
73 {{ arg.name()|check_lower_rb(arg.as_type().borrow()) }}
74 {%- endfor %}
75 {%- endmacro -%}