Просмотр исходного кода

Clarify documentation for Node regarding usage.

Gustavo Niemeyer 7 лет назад
Родитель
Сommit
0b8d56a98d
1 измененных файлов с 16 добавлено и 3 удалено
  1. 16 3
      yaml.go

+ 16 - 3
yaml.go

@@ -326,9 +326,22 @@ const (
 // Node represents an element in the YAML document hierarchy. While documents
 // are typically encoded and decoded into higher level types, such as structs
 // and maps, Node is an intermediate representation that allows detailed
-// control over the content being decoded or encoded. It may be used entirely
-// by itself, or composed together with other types. For example, it may be
-// used as the type of a single field of a structure being decoded.
+// control over the content being decoded or encoded. It encodes and decodes
+// just like any other type, using the Marshal and Unmarshal functions, or the
+// Encoder and Decoder types, and just like any other type it can be mixed
+// together in existing types (structs, maps, etc). For example:
+//
+//     var person struct {
+//             Name    string
+//             Address yaml.Node
+//     }
+//     err := yaml.Unmarshal(data, &person)
+// 
+// Or by itself:
+//
+//     var person Node
+//     err := yaml.Unmarshal(data, &person)
+//
 type Node struct {
 	// Kind defines whether the node is a document, a mapping, a sequence,
 	// a scalar value, or an alias to another node. The specific data type of