alef 0.85.12

Opinionated polyglot binding generator for Rust libraries
Documentation
import {{ package_name }}.*
{% if is_streaming %}import kotlinx.coroutines.flow.collect
{% endif %}{% if needs_mapper %}import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
{% endif %}

fun main() {% if is_async %}= kotlinx.coroutines.runBlocking {% endif %}{
{% if needs_mapper %}    val mapper = jacksonObjectMapper().setPropertyNamingStrategy(com.fasterxml.jackson.databind.PropertyNamingStrategies.SNAKE_CASE)
{% endif %}
{% if expects_error %}    try {
{% endif %}
{% for line in setup_lines %}    {{ line }}
{% endfor %}
{% if client_factory %}    val apiKey = requireNotNull(System.getenv("{{ api_key_var }}")) { "{{ api_key_var }} must be set" }
{% if is_streaming %}    {{ class_name }}.{{ client_factory }}(apiKey = apiKey{% if base_url %}, baseUrl = "{{ base_url }}"{% endif %}).use { client ->
        client.{{ function_name }}({{ args }}).collect { {{ stream_item }} ->
{% elif returns_void %}    {{ class_name }}.{{ client_factory }}(apiKey = apiKey{% if base_url %}, baseUrl = "{{ base_url }}"{% endif %}).use { client -> client.{{ function_name }}({{ args }}) }
{% else %}    val {{ result_var }} = {{ class_name }}.{{ client_factory }}(apiKey = apiKey{% if base_url %}, baseUrl = "{{ base_url }}"{% endif %}).use { client -> client.{{ function_name }}({{ args }}) }
{% endif %}
{% elif is_streaming %}    {{ class_name }}.{{ function_name }}({{ args }}).collect { {{ stream_item }} ->
{% elif returns_void %}    {{ class_name }}.{{ function_name }}({{ args }})
{% else %}    val {{ result_var }} = {{ class_name }}.{{ function_name }}({{ args }})
{% endif %}
{% if not expects_error and not returns_void %}
{% if presentation %}
{% for operation in presentation %}
{% if operation.kind == "show" %}
    println({{ operation.expression }})
{% else %}
    for ({{ operation.item }} in {{ operation.expression }}{% if operation.optional %}.orEmpty(){% endif %}) {
{% for field in operation.fields %}
        println({{ field }})
{% endfor %}
    }
{% endif %}
{% endfor %}
{% else %}
    println({% if is_streaming %}{{ stream_item }}{% else %}{{ result_var }}{% endif %})
{% endif %}
{% endif %}
{% if is_streaming %}    }
{% if client_factory %}    }
{% endif %}{% endif %}
{% if expects_error %}    } catch (error: Exception) {
        System.err.println("${error::class.simpleName}: ${error.message}")
    }
{% endif %}
}