github.com/gopherjs/gopherjs@v1.19.0-beta1.0.20240506212314-27071a8796e4/compiler/typesutil/map.go (about)

     1  package typesutil
     2  
     3  import (
     4  	"go/types"
     5  
     6  	"golang.org/x/tools/go/types/typeutil"
     7  )
     8  
     9  // Map is a type-safe wrapper around golang.org/x/tools/go/types/typeutil.Map.
    10  type Map[Val any] struct{ impl typeutil.Map }
    11  
    12  func (m *Map[Val]) At(key types.Type) Val {
    13  	val := m.impl.At(key)
    14  	if val != nil {
    15  		return val.(Val)
    16  	}
    17  	var zero Val
    18  	return zero
    19  }
    20  
    21  func (m *Map[Val]) Set(key types.Type, value Val) (prev Val) {
    22  	old := m.impl.Set(key, value)
    23  	if old != nil {
    24  		return old.(Val)
    25  	}
    26  	var zero Val
    27  	return zero
    28  }
    29  
    30  func (m *Map[Val]) Delete(key types.Type) bool { return m.impl.Delete(key) }
    31  
    32  func (m *Map[Val]) Len() int { return m.impl.Len() }
    33  
    34  func (m *Map[Val]) String() string { return m.impl.String() }