contracts

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MustVerify

func MustVerify(v any)

MustVerify is like Verify but panics if a contract is violated.

func Verify

func Verify(v any) error

Verify checks if the given instance satisfies all its declared contracts. It scans for fields of type contracts.Implements[T] and validates them.

Types

type Implements

type Implements[T any] struct{}

Implements is a zero-cost marker used to declare that a struct implements an interface T.

Usage:

type MyService struct {
	contracts.Implements[IService]
}

This enables: 1. IDE navigation: Clicking IService takes you to the interface definition. 2. IDE discovery: "Find Usages" on IService will show MyService. 3. Runtime validation: contracts.Verify(&MyService{}) checks if the implementation is valid.

Jump to

Keyboard shortcuts

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