Current section

Files

Jump to
ftpasta src ftpasta_ffi_helpers.erl
Raw

src/ftpasta_ffi_helpers.erl

-module(ftpasta_ffi_helpers).
-export([str_to_charlist/1, charlist_to_str/1, normalise/1, normalise_charlist/1]).
% Translate between Gleam's binary strings and Erlang's list strings.
str_to_charlist(String) -> unicode:characters_to_list(String, unicode).
charlist_to_str(Charlist) -> unicode:characters_to_binary(Charlist).
% Reshape Erlang ok/error values to fit Gleam's Result type.
normalise(ok) -> {ok, nil};
normalise({ok, Value}) -> {ok, Value};
normalise({error, Error}) -> {error, Error}.
% Combination of the above two helper functions.
normalise_charlist({ok, Charlist}) -> {ok, charlist_to_str(Charlist)};
normalise_charlist(T) -> normalise(T).