ifacepropagate

package
v0.0.0-...-1fb1a52 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2021 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PropogateInterfaces

func PropogateInterfaces(
	pkg *packages.Package,
	wrapperFuncName string,
	structSelector string,
	wrappedInterfaces []string,
) (string, error)

PropogateInterfaces wraps the given interface in the given package to allow also implementing a named set of additional interfaces iff the given wrappingInterface also implements them, as determined at runtime.

Let's consider a simple concrete example: Assume we have a package with the following struct:

type foo struct {
    io.Reader
}

Calling:

PropogateInterfaces(pkg, "propagateReader", "f *foo.Reader", []string{"io.Closer"})

Which will generate code for:

func (f *foo) propagateReader() io.Reader {
   // returns a type that implements 'io.Closer' iff f.Reader implements 'io.Closer'
}

Why is this ever useful? See https://medium.com/@cep21/interface-wrapping-method-erasure-c523b3549912

Types

This section is empty.

Jump to

Keyboard shortcuts

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