@@ -21,21 +21,22 @@ type Unmarshaler interface {
21
21
UnmarshalTOML (interface {}) error
22
22
}
23
23
24
- // Unmarshal decodes the contents of `data` in TOML format into a pointer `v`.
24
+ // Unmarshal decodes the contents of data in TOML format into a pointer v.
25
+ //
26
+ // See [Decoder] for a description of the decoding process.
25
27
func Unmarshal (data []byte , v interface {}) error {
26
28
_ , err := NewDecoder (bytes .NewReader (data )).Decode (v )
27
29
return err
28
30
}
29
31
30
32
// Decode the TOML data in to the pointer v.
31
33
//
32
- // See the documentation on Decoder for a description of the decoding process.
34
+ // See [ Decoder] for a description of the decoding process.
33
35
func Decode (data string , v interface {}) (MetaData , error ) {
34
36
return NewDecoder (strings .NewReader (data )).Decode (v )
35
37
}
36
38
37
- // DecodeFile is just like Decode, except it will automatically read the
38
- // contents of the file at path and decode it for you.
39
+ // DecodeFile reads the contents of a file and decodes it with [Decode].
39
40
func DecodeFile (path string , v interface {}) (MetaData , error ) {
40
41
fp , err := os .Open (path )
41
42
if err != nil {
@@ -48,7 +49,7 @@ func DecodeFile(path string, v interface{}) (MetaData, error) {
48
49
// Primitive is a TOML value that hasn't been decoded into a Go value.
49
50
//
50
51
// This type can be used for any value, which will cause decoding to be delayed.
51
- // You can use the PrimitiveDecode() function to "manually" decode these values.
52
+ // You can use [ PrimitiveDecode] to "manually" decode these values.
52
53
//
53
54
// NOTE: The underlying representation of a `Primitive` value is subject to
54
55
// change. Do not rely on it.
@@ -70,15 +71,15 @@ const (
70
71
71
72
// Decoder decodes TOML data.
72
73
//
73
- // TOML tables correspond to Go structs or maps (dealer's choice – they can be
74
- // used interchangeably) .
74
+ // TOML tables correspond to Go structs or maps; they can be used
75
+ // interchangeably, but structs offer better type safety .
75
76
//
76
77
// TOML table arrays correspond to either a slice of structs or a slice of maps.
77
78
//
78
- // TOML datetimes correspond to Go time.Time values . Local datetimes are parsed
79
- // in the local timezone.
79
+ // TOML datetimes correspond to [ time.Time] . Local datetimes are parsed in the
80
+ // local timezone.
80
81
//
81
- // time.Duration types are treated as nanoseconds if the TOML value is an
82
+ // [ time.Duration] types are treated as nanoseconds if the TOML value is an
82
83
// integer, or they're parsed with time.ParseDuration() if they're strings.
83
84
//
84
85
// All other TOML types (float, string, int, bool and array) correspond to the
@@ -90,7 +91,7 @@ const (
90
91
// UnmarshalText method. See the Unmarshaler example for a demonstration with
91
92
// email addresses.
92
93
//
93
- // Key mapping
94
+ // ### Key mapping
94
95
//
95
96
// TOML keys can map to either keys in a Go map or field names in a Go struct.
96
97
// The special `toml` struct tag can be used to map TOML keys to struct fields
@@ -168,17 +169,16 @@ func (dec *Decoder) Decode(v interface{}) (MetaData, error) {
168
169
return md , md .unify (p .mapping , rv )
169
170
}
170
171
171
- // PrimitiveDecode is just like the other `Decode*` functions, except it
172
- // decodes a TOML value that has already been parsed. Valid primitive values
173
- // can *only* be obtained from values filled by the decoder functions,
174
- // including this method. (i.e., `v` may contain more `Primitive`
175
- // values.)
172
+ // PrimitiveDecode is just like the other Decode* functions, except it decodes a
173
+ // TOML value that has already been parsed. Valid primitive values can *only* be
174
+ // obtained from values filled by the decoder functions, including this method.
175
+ // (i.e., v may contain more [Primitive] values.)
176
176
//
177
- // Meta data for primitive values is included in the meta data returned by
178
- // the ` Decode*` functions with one exception: keys returned by the Undecoded
179
- // method will only reflect keys that were decoded. Namely, any keys hidden
180
- // behind a Primitive will be considered undecoded. Executing this method will
181
- // update the undecoded keys in the meta data. (See the example.)
177
+ // Meta data for primitive values is included in the meta data returned by the
178
+ // Decode* functions with one exception: keys returned by the Undecoded method
179
+ // will only reflect keys that were decoded. Namely, any keys hidden behind a
180
+ // Primitive will be considered undecoded. Executing this method will update the
181
+ // undecoded keys in the meta data. (See the example.)
182
182
func (md * MetaData ) PrimitiveDecode (primValue Primitive , v interface {}) error {
183
183
md .context = primValue .context
184
184
defer func () { md .context = nil }()
0 commit comments