Documentation ¶
Overview ¶
The fluent package offers helper utilities for using NodeAssembler more tersely by providing an interface that handles all errors for you, and allows use of closures for any recursive assembly so that creating trees of data results in indentation for legibility.
Note that the fluent package creates wrapper objects in order to provide the API conveniences that it does, and this comes at some cost to performance. If you're optimizing for performance, using the fluent interfaces may be inadvisable. However, as with any performance questions, benchmark before making decisions; its entirely possible that your performance bottlenecks will be elsewhere and there's no reason to deny yourself syntactic sugar if the costs don't detectably affect the bottom line.
Index ¶
- func Build(ns ipld.NodeStyle, fn func(NodeAssembler)) (ipld.Node, error)
- func MustBuild(ns ipld.NodeStyle, fn func(NodeAssembler)) ipld.Node
- func MustBuildList(ns ipld.NodeStyle, sizeHint int, fn func(ListAssembler)) ipld.Node
- func MustBuildMap(ns ipld.NodeStyle, sizeHint int, fn func(MapAssembler)) ipld.Node
- func Recover(fn func()) (err error)
- type Error
- type ListAssembler
- type MapAssembler
- type NodeAssembler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MustBuild ¶ added in v0.0.3
func MustBuild(ns ipld.NodeStyle, fn func(NodeAssembler)) ipld.Node
func MustBuildList ¶ added in v0.0.3
func MustBuildMap ¶ added in v0.0.3
func Recover ¶
func Recover(fn func()) (err error)
Recover invokes a function within a panic-recovering context, and returns any raised fluent.Error values; any other values are re-panicked.
This can be useful for writing large blocks of code using fluent nodes, and handling any errors at once at the end.
Types ¶
type ListAssembler ¶ added in v0.0.3
type ListAssembler interface { AssembleValue() NodeAssembler ValueStyle(idx int) ipld.NodeStyle }
ListAssembler is the same as the interface in the core package, except: instead of returning errors, any error will cause panic (and you can collect these with `fluent.Recover`); and all recursive operations take a function as a parameter, within which you will receive another {Map,List,}NodeAssembler.
type MapAssembler ¶ added in v0.0.3
type MapAssembler interface { AssembleKey() NodeAssembler AssembleValue() NodeAssembler AssembleEntry(k string) NodeAssembler KeyStyle() ipld.NodeStyle ValueStyle(k string) ipld.NodeStyle }
MapAssembler is the same as the interface in the core package, except: instead of returning errors, any error will cause panic (and you can collect these with `fluent.Recover`); and all recursive operations take a function as a parameter, within which you will receive another {Map,List,}NodeAssembler.
type NodeAssembler ¶ added in v0.0.3
type NodeAssembler interface { CreateMap(sizeHint int, fn func(MapAssembler)) CreateList(sizeHint int, fn func(ListAssembler)) AssignNull() AssignBool(bool) AssignInt(int) AssignFloat(float64) AssignString(string) AssignBytes([]byte) AssignLink(ipld.Link) AssignNode(ipld.Node) Style() ipld.NodeStyle }
NodeAssembler is the same as the interface in the core package, except: instead of returning errors, any error will cause panic (and you can collect these with `fluent.Recover`); and all recursive operations take a function as a parameter, within which you will receive another {Map,List,}NodeAssembler.
func WrapAssembler ¶ added in v0.0.3
func WrapAssembler(na ipld.NodeAssembler) NodeAssembler