1 package lib
2 3 // Colour is a four-byte struct, so an interface value holds it INLINE in the
4 // value slot rather than behind a pointer.
5 type Colour struct {
6 R, G, B, A uint8
7 }
8 9 func (c *Colour) RGBA() (r, g, b, a uint8) {
10 return c.R, c.G, c.B, c.A
11 }
12 13 type Color interface {
14 RGBA() (r, g, b, a uint8)
15 }
16 17 // Box returns interface values built in this package's frame, so the caller
18 // only sees them if the return relocation carried them.
19 func Box() (out []Color) {
20 return []Color{
21 Colour{1, 2, 3, 4},
22 Colour{5, 6, 7, 8},
23 }
24 }
25 26 // Sum dispatches through the interface from inside the defining package.
27 func Sum(cs []Color) (out uint8) {
28 r, _, _, _ := cs[0].RGBA()
29 g, _, _, _ := cs[1].RGBA()
30 return r + g
31 }
32