typed

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2019 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ErrNoSuchField

type ErrNoSuchField struct {
	Type schema.Type

	FieldName string
}

ErrNoSuchField may be returned from traversal functions on the Node interface when a field is requested which doesn't exist; it may also be returned during MapBuilder

func (ErrNoSuchField) Error

func (e ErrNoSuchField) Error() string

type Node

type Node interface {
	// typed.Node acts just like a regular Node for almost all purposes;
	// which ReprKind it acts as is determined by the TypeKind.
	// (Note that the representation strategy of the type does *not* affect
	// the ReprKind of typed.Node -- rather, the representation strategy
	// affects the `.Representation().ReprKind()`.)
	//
	// For example: if the `.Type().Kind()` of this node is "struct",
	// it will act like ReprKind() == "map"
	// (even if Type().(Struct).ReprStrategy() is "tuple").
	ipld.Node

	// Type returns a reference to the reified schema.Type value.
	Type() schema.Type

	// Representation returns an ipld.Node which sees the data in this node
	// in its representation form.
	//
	// For example: if the `.Type().Kind()` of this node is "struct",
	// `.Representation().Kind()` may vary based on its representation strategy:
	// if the representation strategy is "map", then it will be ReprKind=="map";
	// if the streatgy is "tuple", then it will be ReprKind=="list".
	Representation() ipld.Node
}

typed.Node is a superset of the ipld.Node interface, and has additional behaviors.

A typed.Node can be inspected for its schema.Type and schema.Kind, which conveys much more and richer information than the Data Model layer ipld.ReprKind.

There are many different implementations of typed.Node. One implementation can wrap any other existing ipld.Node (i.e., it's zero-copy) and promises that it has *already* been validated to match the typesystem.Type; another implementation similarly wraps any other existing ipld.Node, but defers to the typesystem validation checking to fields that are accessed; and when using code generation tools, all of the generated native Golang types produced by the codegen will each individually implement typed.Node.

Note that typed.Node can wrap *other* typed.Node instances. Imagine you have two parts of a very large code base which have codegen'd components which are from different versions of a schema. Smooth migrations and zero-copy type-safe data sharing between them: We can accommodate that!

Jump to

Keyboard shortcuts

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