I have studied this post, but I cannot figure out how to use it in my case.
1st package
I have a 1st package with this type:
type Vertex struct {
X, Y, Z float32
}
There is a slice like:
var V []Vertex
2nd package
There is a 2nd package whose API cannot be modified. In 2nd package, there is this function:
func Compute(points []struct{X, Y, Z float32}) (err error) {
// ...
return
}
Call 2nd package by 1st package
Inside 1st package I intend to call the 2nd package. Without a loop that will copy all the fields from the source to the target:
err = secondpackage.Compute(V)
But I receive this error:
Cannot use 'V' (type []Vertex) as type []struct {...}
Didn't work
Inspired by this post, I tried to convert by:
points := []struct {
X, Y, Z float32
}(V)
err = secondpackage.Compute(points)
But I'm receiving this error:
Cannot convert expression of type '[]Vertex' to type '[]struct { X, Y, Z float32 }'