Advertisement
rhuanpk

Structs in Function Parameters

May 15th, 2023
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.58 KB | Source Code | 0 0
  1. package main
  2.  
  3. import "fmt"
  4.  
  5. type mainStruct[Type any] struct {
  6.     firstField  string
  7.     secondField bool
  8.     slaveStruct slaveStruct
  9.     Struct      Type
  10. }
  11.  
  12. type slaveStruct struct {
  13.     firstField  string
  14.     secondField bool
  15. }
  16.  
  17. type otherStruct struct {
  18.     firstField  string
  19.     secondField bool
  20. }
  21.  
  22. func makeStruct[Type any](source *Type) *mainStruct[Type] {
  23.     return &mainStruct[Type]{
  24.         firstField:  "",
  25.         secondField: false,
  26.         slaveStruct: slaveStruct{},
  27.         Struct:      *source,
  28.     }
  29. }
  30.  
  31. func main() {
  32.     fullStruct := makeStruct(&otherStruct{})
  33.     fmt.Printf("%+v\n", *fullStruct)
  34. }
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement