# `Macaw.Layers.Digest`
[🔗](https://github.com/dcoai/macaw_layers/blob/v0.4.0/lib/macaw/layers/digest.ex#L1)

What the kernel's digest encodes for a struct (spec/01 §7): 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, as it always was. 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.Layers.Digest, for: MyApp.Chunked do
      def canonical(t), do: {"my_app.chunked", MyApp.Chunked.rows(t)}
    end

`Macaw.Layers.Document.digest/1` and `Macaw.Layers.Document.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*
