| 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "fmt" |
| 5 | ) |
| 6 | |
| 7 | func MapOf[K comparable, V any](m map[K]V) Map[K, V] { |
| 8 | return Map[K, V]{m} |
| 9 | } |
| 10 | |
| 11 | type Map[K comparable, V any] struct { |
| 12 | ж map[K]V |
| 13 | } |
| 14 | |
| 15 | func (v MapView) Int() Map[string, int] { return MapOf(v.ж.Int) } |
| 16 | |
| 17 | type VMap struct { |
| 18 | Int map[string]int |
| 19 | } |
| 20 | |
| 21 | type MapView struct { |
| 22 | ж *VMap |
| 23 | } |
| 24 | |
| 25 | func main() { |
| 26 | mv := MapView{&VMap{}} |
| 27 | fmt.Println(mv.ж) |
| 28 | } |
| 29 | |
| 30 | // Output: |
| 31 | // &{map[]} |