wit-bindgen icon indicating copy to clipboard operation
wit-bindgen copied to clipboard

C#: Consider changing `List` parameters to e.g. `IEnumerable`

Open dicej opened this issue 1 year ago • 2 comments

Per https://github.com/dotnet/runtimelab/pull/2614#discussion_r1699995101, List parameters are often unnecessarily restrictive -- callers might want to pass collections of other types without converting them to Lists first.

dicej avatar Aug 01 '24 14:08 dicej

note that IEnumerable doesn't have Count/Length but you will likely need to know it upfront to allocate for marshaling. So maybe other interfaces I mentioned would be better fit. Or you could even generate multiple signatures.

pavelsavara avatar Aug 01 '24 14:08 pavelsavara

I don't know if we also marshal arrays of structs and primitive types (not resources), but in such case Span<T> and ReadOnlySpan<T> are better choices. Because those could live on stack. It would also help with stream APIs

pavelsavara avatar Aug 01 '24 14:08 pavelsavara