FAQ
The following is a go playground link to a snippet that embodies the
problem:

http://play.golang.org/p/jOsvD0msJX

When trying to build, the following error is displayed:

./main.go:24: cannot use b.Guts (type []*MyGut) as type []Gut in return
argument

Background:
I am using protocol buffers and would like to retrofit an interface so I
can abstract the protocol buffers away (to swap out different concrete
types as needed). Since the protocol buffer is auto-generated, I can't
modify the associated files directly without it being entirely wiped every
time I re-generate. So, I was wondering if there is a way to get the code
to work without changing the type in the MyBody struct.

How do I get this to work?

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

  • Rob Pike at Aug 30, 2013 at 1:17 am
    http://golang.org/doc/faq#convert_slice_of_interface

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Gregory Pinto at Aug 30, 2013 at 2:05 am
    Well that would explain that. The overhead this would incur is a bit too
    steep for my purposes, is there any other way? Also, can you or someone
    else please explain in more detail the technical reasons behind this?
    On Thursday, August 29, 2013 6:16:40 PM UTC-7, Rob Pike wrote:

    http://golang.org/doc/faq#convert_slice_of_interface
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Jesse McNelis at Aug 30, 2013 at 2:35 am

    On Fri, Aug 30, 2013 at 12:05 PM, wrote:

    Well that would explain that. The overhead this would incur is a bit too
    steep for my purposes, is there any other way? Also, can you or someone
    else please explain in more detail the technical reasons behind this?
    On Thursday, August 29, 2013 6:16:40 PM UTC-7, Rob Pike wrote:

    http://golang.org/doc/faq#convert_slice_of_interface
    A pointer and an interface value are difference sizes.
    http://research.swtch.com/interfaces

    In a language like Java where every value is the same size(a pointer) this
    is simple, In Go it requires copying.

    --
    =====================
    http://jessta.id.au

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedAug 30, '13 at 1:10a
activeAug 30, '13 at 2:35a
posts4
users3
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase