Macaw.Layers.Digest protocol (macaw_layers v0.4.0)

Copy Markdown View Source

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.

Summary

Types

t()

All the types that implement this protocol.

Functions

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

Types

t()

@type t() :: term()

All the types that implement this protocol.

Functions

canonical(value)

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

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