package lib // Colour is a four-byte struct, so an interface value holds it INLINE in the // value slot rather than behind a pointer. type Colour struct { R, G, B, A uint8 } func (c *Colour) RGBA() (r, g, b, a uint8) { return c.R, c.G, c.B, c.A } type Color interface { RGBA() (r, g, b, a uint8) } // Box returns interface values built in this package's frame, so the caller // only sees them if the return relocation carried them. func Box() (out []Color) { return []Color{ Colour{1, 2, 3, 4}, Colour{5, 6, 7, 8}, } } // Sum dispatches through the interface from inside the defining package. func Sum(cs []Color) (out uint8) { r, _, _, _ := cs[0].RGBA() g, _, _, _ := cs[1].RGBA() return r + g }