Current section
Files
Jump to
Current section
Files
src/sprocket@internal@utils@unique.erl
-module(sprocket@internal@utils@unique).
-compile([no_auto_import, nowarn_unused_vars]).
-export([new/0, from_string/1, to_string/1, equals/2]).
-export_type([unique/0]).
-opaque unique() :: {unique, binary()}.
-spec new() -> unique().
new() ->
_assert_subject = sprocket@internal@utils@uuid:v4(),
{ok, Id} = case _assert_subject of
{ok, _} -> _assert_subject;
_assert_fail ->
erlang:error(#{gleam_error => assert,
message => <<"Assertion pattern match failed"/utf8>>,
value => _assert_fail,
module => <<"sprocket/internal/utils/unique"/utf8>>,
function => <<"new"/utf8>>,
line => 8})
end,
{unique, Id}.
-spec from_string(binary()) -> unique().
from_string(Str) ->
{unique, Str}.
-spec to_string(unique()) -> binary().
to_string(Unique) ->
erlang:element(2, Unique).
-spec equals(unique(), unique()) -> boolean().
equals(A, B) ->
erlang:element(2, A) =:= erlang:element(2, B).