View Source Bunch.ShortRef (Bunch v1.3.2)
A wrapper over Erlang/Elixir references that makes them more readable and visually distinguishable.
When printed, Erlang references are quite long:
Moreover, since they're based on an incremented counter, it's hard to distinguish
between a two created within the same period of time, like
Bunch.ShortRef.t/0 stores a usual reference along with first 4 bytes
of its SHA1 hash and when inspected prints only 8 hex digits prepended with
Thanks to use of the hash function, similar references have totally different
string representations - the case from the previous example would be
When to use
Bunch.ShortRef should be used when a reference is to be printed or logged.
It should NOT be used when creating lots of references as it adds a significant
Link to this section Summary
Link to this section Types
Link to this section Functions
Creates a short reference.
iex> IEx.Helpers.ref(0, 1, 2, 3) |> Bunch.ShortRef.new() |> inspect() "#82c033ef" iex> <<"#", hash::binary-size(8)>> = Bunch.ShortRef.new() |> inspect() iex> Base.decode16(hash, case: :lower) |> elem(0) :ok