package main

import "fmt"

type Distance float64

func (d Distance) String() string {
	return fmt.Sprintf("%.2f meters", d)
}

// section: comparison
// Type definition - methods DON'T promote
type Height Distance // Height does NOT have Distance's methods

// Embedding - methods DO promote
type Person struct {
	Distance // Person DOES have Distance's methods via embedding
}

// section: comparison

func main() {
	// section: main
	var h Height = 100
	// h.String() // ERROR - Height has no String method
	fmt.Printf("Height: %v (no String method)\n", h)

	p := Person{Distance: 100}
	fmt.Printf("Person: %s\n", p.String()) // Works! Method promoted from embedded Distance
	// section: main
}

/*
// section: output
$ go run main.go
Height: 100 (no String method)
Person: 100.00 meters
// section: output
*/
