ExamplePointer_Set_appendTopLevelSlice shows the one case where the returned document is load-bearing: appending to a top-level slice passed by value. The library cannot rebind the slice header in the caller's variable, so callers must use the returned document (or pass *[]T to get in-place rebind)
()
| 163 | // The library cannot rebind the slice header in the caller's variable, so callers must use the |
| 164 | // returned document (or pass *[]T to get in-place rebind). |
| 165 | func ExamplePointer_Set_appendTopLevelSlice() { |
| 166 | doc := []int{1, 2} |
| 167 | |
| 168 | pointer, err := New("/-") |
| 169 | if err != nil { |
| 170 | fmt.Println(err) |
| 171 | |
| 172 | return |
| 173 | } |
| 174 | |
| 175 | out, err := pointer.Set(doc, 3) |
| 176 | if err != nil { |
| 177 | fmt.Println(err) |
| 178 | |
| 179 | return |
| 180 | } |
| 181 | |
| 182 | fmt.Printf("original: %v\n", doc) |
| 183 | fmt.Printf("returned: %v\n", out) |
| 184 | |
| 185 | // Output: |
| 186 | // original: [1 2] |
| 187 | // returned: [1 2 3] |
| 188 | } |
| 189 | |
| 190 | // ExampleUseGoNameProvider contrasts the two [NameProvider] implementations shipped by |
| 191 | // [github.com/go-openapi/jsonpointer/jsonname]: |