Toon.Encoder protocol (toon v0.3.0)
View SourceProtocol for encoding custom data structures to TOON format.
This protocol allows you to define how your custom structs should be
encoded to TOON format, similar to Jason.Encoder.
Example
defmodule User do
@derive {Toon.Encoder, only: [:name, :email]}
defstruct [:id, :name, :email, :password_hash]
endOr implement the protocol manually:
defimpl Toon.Encoder, for: User do
def encode(user, opts) do
%{
"name" => user.name,
"email" => user.email
}
|> Toon.Encode.encode!(opts)
end
end
Summary
Functions
Encodes the given value to TOON format.
Types
@type t() :: term()
All the types that implement this protocol.