# `RDF.Serialization.Encoder`
[🔗](https://github.com/rdf-elixir/rdf-ex/blob/v3.0.1/lib/rdf/serialization/encoder.ex#L1)

A behaviour for encoders of RDF data structures in a specific `RDF.Serialization` format.

# `encode`

```elixir
@callback encode(RDF.Data.Source.t()) :: {:ok, String.t()} | {:error, any()}
```

Serializes an RDF data structure into a string.

It should return an `{:ok, string}` tuple, with `string` being the serialized
RDF data structure, or `{:error, reason}` if an error occurs.

# `encode`

```elixir
@callback encode(
  RDF.Data.Source.t(),
  keyword()
) :: {:ok, String.t()} | {:error, any()}
```

Serializes an RDF data structure into a string.

It should return an `{:ok, string}` tuple, with `string` being the serialized
RDF data structure, or `{:error, reason}` if an error occurs.

# `encode!`

```elixir
@callback encode!(RDF.Data.Source.t()) :: String.t()
```

Serializes an RDF data structure into a string.

As opposed to `encode`, it raises an exception if an error occurs.

Note: The `__using__` macro automatically provides an overridable default
implementation based on the non-bang `encode` function.

# `encode!`

```elixir
@callback encode!(
  RDF.Data.Source.t(),
  keyword()
) :: String.t()
```

Serializes an RDF data structure into a string.

As opposed to `encode`, it raises an exception if an error occurs.

Note: The `__using__` macro automatically provides an overridable default
implementation based on the non-bang `encode` function.

# `stream`
*optional* 

```elixir
@callback stream(
  RDF.Data.Source.t(),
  keyword()
) :: Enumerable.t()
```

Serializes an RDF data structure into a stream.

It should return a stream emitting either strings or iodata of the
serialized RDF data structure. If both forms are supported the form
should be configurable via the `:mode` option and its values `:string`
respective `:iodata`.

---

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