Masu.Wire protocol (Masu v0.7.0)

Copy Markdown View Source

A value of your own type, as the browser gets it in a cell: what the cell shows (formatted by the column's type), what a copy and an export take, and what a filter of the browser compares.

Masu knows numbers, decimals, dates and times, booleans and text, and a struct that implements String.Chars. For any other struct, implement this protocol: a rich text that shows its text, a range of days that shows 2027-03-15/2027-03-20.

defimpl Masu.Wire, for: Kotoba.Content do
  def to_wire(content), do: content.text
end

defimpl Masu.Wire, for: Koyomi.DateRange do
  def to_wire(range), do: "#{range.from}/#{range.to}"
end

The value goes to the browser as JSON: give text, a number, a boolean, or nil. An editor of your own (see the Editors of your own guide) gets the value as the row has it, not this.

Summary

Types

t()

All the types that implement this protocol.

Functions

The value as the browser gets it.

Types

t()

@type t() :: term()

All the types that implement this protocol.

Functions

to_wire(value)

@spec to_wire(t()) :: String.t() | number() | boolean() | nil

The value as the browser gets it.