Skip to content

Commit

Permalink
Document the preference for non-pointer links.
Browse files Browse the repository at this point in the history
  • Loading branch information
warpfork committed Dec 1, 2020
1 parent 96aa55e commit 8125cac
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions linking.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ import (
// It's even possible to use IPLD *entirely without* any linking implementation,
// using it purely for json/cbor via the encoding packages and
// foregoing the advanced traversal features around transparent link loading.
//
// Link interfaces are usually inhabited by a struct or string or etc, and not a pointer.
// This is because Link is often desirable to be able to use as a golang map key,
// and in that context, pointers would not result in the desired behavior.
type Link interface {
// Load consumes serial data from a Loader and funnels the parsed
// data into a NodeAssembler.
Expand Down
7 changes: 7 additions & 0 deletions linking/cid/cidLink.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ var (
_ ipld.LinkBuilder = LinkBuilder{}
)

// Link implements the ipld.Link interface using a CID.
// See https://github.com/ipfs/go-cid for more information about CIDs.
//
// When using this value, typically you'll use it as `Link`, and not `*Link`.
// This includes when handling the value as an `ipld.Link` interface -- the non-pointer form is typically preferable.
// This is because the ipld.Link inteface is often desirable to be able to use as a golang map key,
// and in that context, pointers would not result in the desired behavior.
type Link struct {
cid.Cid
}
Expand Down

0 comments on commit 8125cac

Please # to comment.