I was mainly mirroring the encoding/json API.
It was also to (later on) be able to type-switch on types that implement
the SCFG (un)marshaling interface (or just use reflect).
but I didn't want to write that before the patch you mention was merged
into main :)
ie:
```go
type T1 struct {
Listen []string `scfg:"listen"`
}
type T2 struct {
Listen []string
}
func (t2 T2) MarshalSCFG() ([]byte, error) { ... }
var (
t1 T1
t2 T2
blk scfg.Block
enc = scfg.NewEncoder(os.Stdout)
)
err = enc.Encode(t1) // use reflect (TODO)
err = enc.Encode(t2) // use MarshalSCFG (TODO)
err = enc.Encode(blk) // ok
```
enc.Encode(blk) mirrors what can be done with:
```go
var (
msg = json.RawMessage(`{"hello":"world"}`)
err = json.NewEncoder(os.Stdout).Encode(msg)
)
```
That makes sense! That said, I'd still prefer to hold off exposing a public API
until we actually have a use for it. In other words, I'd prefer to only expose
Write for now, and add Marshal/Encoder when we actually implement the new
functionality.
Do we really need to use interface{} here? What is the use-case for passing a
Directive?
More generally, I'd prefer to reserve Marshal/Encoder abstractions for
formatting scfg from arbitrary Go types, such as done in [1].
[1]: https://lists.sr.ht/~emersion/public-inbox/patches/42271