From 76d181441f23911a8597b09444a9d323d9e5d246 Mon Sep 17 00:00:00 2001 From: Wilhelm Kirschbaum Date: Sat, 23 Nov 2024 10:58:36 +0200 Subject: [PATCH] fix: use String.Chars.t() instead of binary() for put_toast message The message does not have to be a binary, but needs to implement String.Chars for it to be rendered. This allows structs to be used like ErrorMessage without having to call to_string(error). --- lib/live_toast.ex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/live_toast.ex b/lib/live_toast.ex index a597590..2450399 100644 --- a/lib/live_toast.ex +++ b/lib/live_toast.ex @@ -100,12 +100,12 @@ defmodule LiveToast do """ def put_toast(conn_or_socket, kind, msg, options \\ []) - @spec put_toast(Plug.Conn.t(), atom(), binary(), [option()]) :: Plug.Conn.t() + @spec put_toast(Plug.Conn.t(), atom(), String.Chars.t(), [option()]) :: Plug.Conn.t() def put_toast(%Plug.Conn{} = conn, kind, msg, _options) do Phoenix.Controller.put_flash(conn, kind, msg) end - @spec put_toast(LiveView.Socket.t(), atom(), binary(), [option()]) :: LiveView.Socket.t() + @spec put_toast(LiveView.Socket.t(), atom(), String.Chars.t(), [option()]) :: LiveView.Socket.t() def put_toast(%LiveView.Socket{} = socket, kind, msg, options) do send_toast(kind, msg, options)