# `Macaw.Base.Digest`
[🔗](https://github.com/dcoai/macaw_base/blob/v0.1.1/lib/macaw/base/digest.ex#L1)

What the canonical encoding writes for a struct (spec/01 §5): its **canonical term**.

A struct whose fields are its contents (a schema, a `DateTime`) needs nothing: it is
encoded as its map, `__struct__` and all. A struct whose fields are a *layout* of its
contents implements this protocol and answers the term its identity is, so two equal
values laid out differently get one digest:

    defimpl Macaw.Base.Digest, for: MyApp.Chunked do
      def canonical(t), do: {"my_app.chunked", MyApp.Chunked.rows(t)}
    end

`Macaw.Base.Encoding.digest/1` and `Macaw.Base.Encoding.encode/1` encode a struct as its
canonical term wherever it appears, nested in maps, lists and tuples too. The term
answered must be data, and is itself encoded as any term is, a struct in it by its own
canonical term.

# `t`

```elixir
@type t() :: term()
```

All the types that implement this protocol.

# `canonical`

```elixir
@spec canonical(t()) :: term()
```

The term a struct's digest encodes in its place.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
