uniffi_bindgen 0.32.0

a multi-language bindings generator for rust (codegen and cli tooling)
Documentation
# This file was autogenerated by some hot garbage in the `uniffi` crate.
# Trust me, you don't want to mess with it!

# Common helper code.
#
# Ideally this would live in a separate .rb file where it can be unittested etc
# in isolation, and perhaps even published as a re-useable package.
#
# However, it's important that the details of how this helper code works (e.g. the
# way that different builtin types are passed across the FFI) exactly match what's
# expected by the rust code on the other side of the interface. In practice right
# now that means coming from the exact some version of `uniffi` that was used to
# compile the rust component. The easiest way to ensure this is to bundle the Ruby
# helpers directly inline like we're doing here.

require 'ffi'
require 'set'

{%- if ci.has_callback_definitions() || ci.has_async_fns() %}
require 'monitor'
{%- endif %}

module {{ ci.namespace()|class_name_rb }}
  {% include "Helpers.rb" %}

  {%- if ci.has_callback_definitions() %}
  {% include "HandleMap.rb" %}
  {%- endif %}
  {%- if ci.has_async_fns() && !ci.has_callback_definitions() %}
  {% include "HandleMap.rb" %}
  {%- endif %}
  {% include "RustBufferTemplate.rb" %}
  {% include "RustBufferStream.rb" %}
  {% include "RustBufferBuilder.rb" %}

  # Error definitions
  {% include "ErrorTemplate.rb" %}

  {% include "NamespaceLibraryTemplate.rb" %}
  {%- if ci.has_async_fns() %}
  {% include "Async.rb" %}
  {%- endif %}
  {%- if ci.has_callback_definitions() %}
  {% include "CallbackInterfaceRuntime.rb" %}
  {%- endif %}

  # Custom type definitions.

  {%- for type_ in ci.iter_local_types() -%}
  {%- match type_ -%}
  {%- when Type::Custom { name, builtin, .. } -%}
  {%- if !ci.is_external(type_) %}
  {% include "CustomTypeTemplate.rb" %}
  {%- else -%}
  {%- match config.custom_types.get(name.as_str()) %}
  {%- when Some(cfg) %}
  {%- match cfg.imports %}
  {%- when Some(imports) %}
  # External custom type `{{ name }}`: importing configured dependencies.
  {%- for import_name in imports %}
  require '{{ import_name }}'
  {%- endfor %}
  {%- when None %}
  {%- endmatch %}
  {%- when None %}
  {%- endmatch %}
  {%- endif %}
  {%- else -%}
  {%- endmatch %}
  {%- endfor %}

  # Public interface members begin here.

  {% for e in ci.enum_definitions() %}
  {% if !ci.is_name_used_as_error(e.name()) %}
  {% include "EnumTemplate.rb" %}
  {% endif %}
  {%- endfor -%}

  {%- for rec in ci.record_definitions() %}
  {% include "RecordTemplate.rb" %}
  {% endfor %}

  {% for func in ci.function_definitions() %}
  {% include "TopLevelFunctionTemplate.rb" %}
  {% endfor %}

  {% for obj in ci.object_definitions() %}
  {% include "ObjectTemplate.rb" %}
  {% endfor %}

  {% for cbi in ci.callback_interface_definitions() %}
  {%- let name = cbi.name() %}
  {% include "CallbackInterfaceTemplate.rb" %}
  {% endfor %}
end

{% import "macros.rb" as rb %}