mirror

package module
v0.0.0-...-197ef17 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2013 License: MPL-2.0 Imports: 2 Imported by: 1

README

Mirror

Build Status Make unsafe code safer by seeing it in the mirror.

Mirror allows you to compare before you cast. Use it in init or with sync.Once to know you can safely cast a struct to another with unsafe because their memory layout is the same.

Access unexported fields without a headache. It may even be rather safe if you only read from them.

Documentation lives at godoc.org.

License: MPL2.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CanConvert

func CanConvert(from, to reflect.Type) bool

CanConvert returns true if the memory layout and the struct field names of 'from' match those of 'to'.

func Walk

func Walk(t reflect.Type, visit VisitType) error

Walk will call visit on t and each type in t. It will follow struct fields, pointers, arrays, slices, maps and chans and call visit on each element. Walk will only follow into types at their very first occurence during this walk.

Types

type VisitType

type VisitType func(typ *reflect.StructField, typeIndex, depth int) error

VisitType processes type information. It is called by Walk. - typ is:

  • a wrapped type (if len(typ.Index) == 0)
  • an interface method (type.Index[0] < 0; ignore first value); this is clumsy...
  • a field of a struct

- typeIndex is the unique index of this type in the set types enountered during a walk - depth counts the number of indirections used to get to this type from the root type

- for a map, the key and the element types are visited - for a function, the input argument types and output argument types are visited - for an interface, all contained functions are visited

Jump to

Keyboard shortcuts

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