Skip to content

Commit

Permalink
Added encodable type for encode functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
azizk committed Oct 15, 2023
1 parent f0f8590 commit ffc600d
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/jason.ex
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ defmodule Jason do
@type value :: nil | String.t() | number | boolean | [value] | %{String.t() => value}
@typedoc "A decoded JSON value where map keys can have any type."
@type decoded :: [decoded] | %{map_key => decoded} | value
@typedoc "The types that may be encoded. Only tuples are not included."
@type encodable :: decoded | atom

@doc """
Parses a JSON value from `input` iodata.
Expand Down Expand Up @@ -143,7 +145,7 @@ defmodule Jason do
{:error, %Jason.EncodeError{message: "invalid byte 0xFF in <<255>>"}}
"""
@spec encode(decoded, [encode_opt]) ::
@spec encode(encodable, [encode_opt]) ::
{:ok, String.t()} | {:error, EncodeError.t() | Exception.t()}
def encode(input, opts \\ []) do
case do_encode(input, format_encode_opts(opts)) do
Expand All @@ -167,7 +169,7 @@ defmodule Jason do
** (Jason.EncodeError) invalid byte 0xFF in <<255>>
"""
@spec encode!(decoded, [encode_opt]) :: String.t() | no_return
@spec encode!(encodable, [encode_opt]) :: String.t() | no_return
def encode!(input, opts \\ []) do
case do_encode(input, format_encode_opts(opts)) do
{:ok, result} -> IO.iodata_to_binary(result)
Expand All @@ -194,7 +196,7 @@ defmodule Jason do
{:error, %Jason.EncodeError{message: "invalid byte 0xFF in <<255>>"}}
"""
@spec encode_to_iodata(decoded, [encode_opt]) ::
@spec encode_to_iodata(encodable, [encode_opt]) ::
{:ok, iodata} | {:error, EncodeError.t() | Exception.t()}
def encode_to_iodata(input, opts \\ []) do
do_encode(input, format_encode_opts(opts))
Expand All @@ -216,7 +218,7 @@ defmodule Jason do
** (Jason.EncodeError) invalid byte 0xFF in <<255>>
"""
@spec encode_to_iodata!(decoded, [encode_opt]) :: iodata | no_return
@spec encode_to_iodata!(encodable, [encode_opt]) :: iodata | no_return
def encode_to_iodata!(input, opts \\ []) do
case do_encode(input, format_encode_opts(opts)) do
{:ok, result} -> result
Expand Down

0 comments on commit ffc600d

Please sign in to comment.