github.com/gnolang/gno@v0.0.0-20240520182011-228e9d0192ce/gnovm/tests/files/interface40b.gno (about)

     1  package main
     2  
     3  type foo struct {
     4  	bar string
     5  }
     6  
     7  func (f foo) String() string {
     8  	return "Hello from " + f.bar
     9  }
    10  
    11  type Stringer interface {
    12  	String() string
    13  }
    14  
    15  func Foo(s string) Stringer {
    16  	return foo{s}
    17  }
    18  
    19  func main() {
    20  	f := Foo("bar")
    21  	println(f.String())
    22  }
    23  
    24  // Output:
    25  // Hello from bar