The String.Chars protocol is responsible for converting a structure to a binary (only if applicable).
The only function required to be implemented is to_string/1, which does the conversion.
The to_string/1 function automatically imported by Kernel invokes this protocol. String interpolation also invokes to_string/1 in its arguments. For example, "foo#{bar}" is the same as "foo" <> to_string(bar).
All the types that implement this protocol.
Converts term to a string.
@type t() :: term()
All the types that implement this protocol.
@spec to_string(t()) :: String.t()
Converts term to a string.
© 2012-2024 The Elixir Team
Licensed under the Apache License, Version 2.0.
https://hexdocs.pm/elixir/1.18.1/String.Chars.html