Documentation
¶
Overview ¶
Package pragma provides zero-cost compile-time type constraints for Go structs. These types are used as embedded fields to enforce certain properties at compile time.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type NoCompare ¶
type NoCompare [0]func()
NoCompare can be embedded in a struct to prevent comparison operations. This is useful for types that should not be compared with == or !=. Uses a zero-length array of functions, which are not comparable in Go.
type NoCopy ¶
type NoCopy [0]noCopy
NoCopy can be embedded in a struct to prevent copying. The go vet tool will detect when a struct with NoCopy is copied by value. Uses a zero-length array of noCopy, which implements the sync.Locker interface to trigger vet's copy checker.
type NoUnkeyedLiterals ¶
type NoUnkeyedLiterals struct{}
NoUnkeyedLiterals can be embedded in a struct to prevent unkeyed literals. This forces users to use field names when initializing the struct, making the code more maintainable.
Example:
type Config struct {
_ pragma.NoUnkeyedLiterals
Host string
Port int
}
// Config{"localhost", 8080} // won't compile
// Config{Host: "localhost", Port: 8080} // OK