NordSecurity / uniffi-bindgen-cs

C# bindings generator for uniffi-rs
https://github.com/NordSecurity/uniffi-bindgen-cs
Mozilla Public License 2.0
110 stars 21 forks source link

Empty struct causes errors in generated code #75

Closed itrumper closed 1 month ago

itrumper commented 9 months ago

Given the following Rust struct:

#[derive(Record)]
struct Test {}

the generated C# code is:

public record Test (
) {
}

class FfiConverterTypeTest: FfiConverterRustBuffer<Test> {
    public static FfiConverterTypeTest INSTANCE = new FfiConverterTypeTest();

    public override Test Read(BigEndianStream stream) {
        return new Test(
        );
    }

    public override int AllocationSize(Test value) {
        return;
    }

    public override void Write(Test value, BigEndianStream stream) {
    }
}

which contains the error "CS0126 An object of a type convertible to 'int' is required". This comes from the empty return in the AllocationSize method. Adding a return value of 0 is I think the correct solution, as that is what Rust allocates for this struct. Thoughts?

arg0d commented 9 months ago

Yeah, returning 0 sounds like the right thing to do.