Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

node/bindnode: allow nilable types for IPLD optional/nullable #401

Merged
merged 1 commit into from
Apr 26, 2022
Merged

node/bindnode: allow nilable types for IPLD optional/nullable #401

merged 1 commit into from
Apr 26, 2022

Commits on Apr 10, 2022

  1. node/bindnode: allow nilable types for IPLD optional/nullable

    For simplicity, bindnode used to always require a pointer to represent
    optional or nullable IPLD types. This is because we need an extra bit to
    store whether the value is absent or null.
    
    However, some Go types can already store a "nil" value to represent that
    bit without needing that extra pointer. Most notably:
    
    	[]T            versus *[]T
    	map[K]V        versus *map[K]V
    	datamodel.Node versus *datamodel.Node
    
    Avoiding the extra pointer makes the types easier for humans to deal
    with, and it also avoids a potential footgun due to the extra "nil"
    state that bindnode doesn't actually use.
    
    Note that we still require pointers for "optional nullable" struct
    fields, as those need two extra bits. A TODO is left for that edge case.
    
    Fixes #378.
    mvdan committed Apr 10, 2022
    Configuration menu
    Copy the full SHA
    de57879 View commit details
    Browse the repository at this point in the history