The methods are defined inside the struct namespace as shown below, which means all the methods should be defined within the same file that is defining the struct, my question if I want to define some methods in separate files, can I attach them to the struct,bis there any thing like the GO reciever like func (v Vec) int(){} or some thing like Rust impl as impl Vec3 {fn init()..} or impl X for Vec3 {}?
const Vec3 = struct {
x: f32,
y: f32,
z: f32,
pub fn init(x: f32, y: f32, z: f32) Vec3 {
return Vec3 {
.x = x,
.y = y,
.z = z,
};
}
pub fn dot(self: Vec3, other: Vec3) f32 {
return self.x * other.x + self.y * other.y + self.z * other.z;
}
};