# `Hakushi.Rules`
[🔗](https://github.com/hattoriai/hakushi/blob/v0.1.0/lib/hakushi/rules.ex#L1)

The rules of the edges of a canvas, the same in the browser and on the
server.

    <.canvas id="flow" graph={@graph} rules={[cycles: false]}>

While a person draws an edge, the browser shows the handles it may end
on, and no others; when the edge comes to the server, the canvas checks
the same rules again, so that a browser that does not follow them still
makes no edge they forbid.

  * `loops` - an edge from a node to itself (`false` unless set).
  * `duplicates` - a second edge between the same two handles, in the
    same direction (`false` unless set).
  * `cycles` - an edge that closes a cycle, as a workflow must not have
    (`true` unless set).

A handle of one `type` connects to a handle that `accepts` it (see
`Hakushi.Components.handle/1`). That rule is the browser's: the server
does not know the handles, which are in the HEEx of each node. Check
what an edge means for your app in `on_change` (see `Hakushi.Change`).

# `reason`

```elixir
@type reason() :: :loop | :duplicate | :cycle
```

Why the rules refuse an edge.

# `t`

```elixir
@type t() :: %Hakushi.Rules{
  cycles: boolean(),
  duplicates: boolean(),
  loops: boolean()
}
```

# `check`

```elixir
@spec check(t(), Hakushi.Graph.t(), Hakushi.Edge.t()) :: :ok | {:error, reason()}
```

Checks an edge against the rules, in a graph that does not have it yet.

# `new`

```elixir
@spec new(t() | keyword() | nil) :: t()
```

Makes rules of a keyword list, or gives rules back.

---

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