alef 0.69.0

Opinionated polyglot binding generator for Rust libraries
Documentation
{% if needs_system %}using System;
{% endif %}
{% if needs_collections %}using System.Collections.Generic;
{% endif %}
{% if needs_json %}using System.Text.Json;
{% endif %}
using {{ namespace }};

{% if needs_json %}var ConfigOptions = new JsonSerializerOptions { PropertyNameCaseInsensitive = true };
{% endif %}
{% if expects_error %}try
{
{% endif %}
{% for line in setup_lines %}{{ line }}
{% endfor %}
{% if client_factory %}var apiKey = Environment.GetEnvironmentVariable("{{ api_key_var }}") ??
  throw new InvalidOperationException("{{ api_key_var }} must be set");
  using var client = {{ class_name }}.{{ client_factory }}({{ client_args }});
  {% if is_streaming %}await foreach (var chunk in client.{{ function_name }}({{ args }}))
  {
      Console.WriteLine(chunk);
  }
  {% elif returns_void %}{% if is_async %}await {% endif %}client.{{ function_name }}({{ args }});
  {% else %}var {{ result_var }} = {% if is_async %}await {% endif %}client.{{ function_name }}({{ args }});
  {% endif %}
{% elif is_streaming %}await foreach (var chunk in {{ class_name }}.{{ function_name }}({{ args }}))
{
    Console.WriteLine(chunk);
}
{% elif returns_void %}{% if is_async %}await {% endif %}{{ class_name }}.{{ function_name }}({{ args }});
{% else %}var {{ result_var }} = {% if is_async %}await {% endif %}{{ class_name }}.{{ function_name }}({{ args }});
{% endif %}
{% if not expects_error and not returns_void and not is_streaming %}
{% if presentation %}
{% for operation in presentation %}
{% if operation.kind == "show" %}
Console.WriteLine({{ operation.expression }});
{% else %}
foreach (var {{ operation.item }} in {{ operation.expression }})
{
{% for field in operation.fields %}
    Console.WriteLine({{ field }});
{% endfor %}
}
{% endif %}
{% endfor %}
{% else %}
Console.WriteLine({{ result_var }});
{% endif %}
{% endif %}
{% if expects_error %}}
catch (Exception error)
{
    Console.Error.WriteLine($"{error.GetType().Name}: {error.Message}");
}
{% endif %}
{% for declaration in visitor_declarations %}
{{ declaration }}
{% endfor %}