alef 0.25.37

Opinionated polyglot binding generator for Rust libraries
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
    /// <summary>Creates a new <see cref="{{ class_name }}"/> handle.</summary>
    public static {{ class_name }} Create({{ param_list }})
    {
        var handle = NativeMethods.{{ native_method }}({{ call_args }});
        if (handle == IntPtr.Zero)
        {
            var ec = NativeMethods.LastErrorCode();
            var ctxPtr = NativeMethods.LastErrorContext();
            var msg = System.Runtime.InteropServices.Marshal.PtrToStringUTF8(ctxPtr) ?? "Create failed";
            throw new {{ exception_name }}(ec, msg);
        }
        return new {{ class_name }}(handle);
    }