typeset

package
v2.0.0-...-87fb603 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 12, 2025 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package typeset handles type stringification and automatic struct aliasing.

A type is "normalized" when all of its previous aliases are resolved, function signature receivers are moved into the first function parameter and all inline struct declarations are replaced with generated aliases.

Normalized types are always assignable to their unnormalized counterparts and vice versa.

TypeSet allows handling all this in a cached manner.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Alias

type Alias struct {
	Name string
	Type *types.Struct
}

type TypeSet

type TypeSet struct {
	// contains filtered or unexported fields
}

TypeSet handles stringification and automatic aliasing of types.

Note that TypeSet includes any function receivers in its stringification (which differs from Go's types package).

TypeSet also automatically creates aliases for struct types so that their strings are kept small. You can query all created aliases with TypeSet.Aliases.

func New

func New(qualifier types.Qualifier) *TypeSet

New creates a new TypeSet.

func (*TypeSet) Aliases

func (ts *TypeSet) Aliases() iter.Seq[Alias]

Aliases returns all aliased structs, sorted by name. Use types.TypeString(Alias.Type, TypeSet.Qualifier) to obtain the code for the referenced struct.

func (*TypeSet) ContainsAlias

func (ts *TypeSet) ContainsAlias(t types.Type) bool

ContainsAlias returns true if the given type is a struct alias within this type set. If ContainsAlias returned true, t is guaranteed to be of type *types.Alias.

func (*TypeSet) Normalized

func (ts *TypeSet) Normalized(typ types.Type) types.Type

Normalized returns the normalized version of typ. Cached for future calls.

func (*TypeSet) Qualifier

func (ts *TypeSet) Qualifier() types.Qualifier

Qualifier returns the qualifier passed at initialization.

func (*TypeSet) TypeString

func (ts *TypeSet) TypeString(t types.Type) string

TypeString returns the qualified string for the type after normalization. The string and normalized type are cached for future calls, and any aliases required are registered.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL