#struct initialization
15 messages · Page 1 of 1 (latest)
no, since struct{rd, wr} would not implement ReaderWriter
an anonymous struct can only implement the interface{} interface since anonymous structs cannot have methods
yeah is there any other way where I could init such type using a oneliner and without introducing another type that embbeds the Reader and Writer structs?
uh
technically you could
here's a hint
var x io.ReadWriter = struct {
io.Reader
io.Writer
}{}
this is wrong, then
uhm.. you mean?
var x io.ReadWriter x := struct {
cReader
cWriter
}{}
not that, but i had another mistake
yes because embedded fields (or promoted methods) are accounted for in interface "satisfaction"
yeah it works
you can do:
var rw ReaderWriter = struct{Reader; Writer}{rd, wr}
thank you for repeating the answer again 