Noob here.
I need to call the function pub fn myFn1(ps: PrivStruc) PrivStruct {...}
where PrivStruct
is a private struct type to which I have no access. The way I do is by passing an anonymous struct as a parameter, something like myFn1(.{ .field1 = 0 })
or myFn1(.{})
where the anonymous struct is coerced into the PrivStruct
type. No problem here.
Now, if I create another function:
fn myFn2(anon: anytype) void {
...
const myPS = myFn1(anon);
...
}
Then if I call myFn2(.{})
I get an error saying PrivStruct
was expected and @TypeOf(.{})
was found, in the myFn1
line. I believe this happens because coercion happens in myFn2
call and after that is pure type compatibility, right ?
Is there a way to myFn1
, inside myFn2
, to “see” anon as an anonymous struct so that coercion happens ? I have tried different solutions using @TypeOf(anon)
but no success.
PrivStruc
is private and uses generics and I cannot use it to type any fn or var, at least not in an easy and straight desirable way.