Type binary() vs String.t()

When adding a @spec to a function, is there any functional difference between doing something like

@spec my_func(input :: binary()) :: any()

vs

@spec my_func(input :: String.t()) :: any()

Does dialyzer treat those differently? A String is a UTF-8 encoded binary, yes? If you were parsing raw binary data (like zeros and ones from an image file), then I would declare the type as binary, but for regular stuff like email addresses, that would be a String.t(), yes?

Just a reality check, soliciting wisdom from the community. Thanks!

1 Like

Dialyzer doesn’t treat them differently. The doc states that they are equivalent to analysis tools and String.t() is defined as @type t() :: binary().

But for clarity, the way you explained you would use them seems right to me.

3 Likes