-module(glethers@primitives@bytes). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). -export([from_bit_array/1, decoder/1, to_bit_array/1]). -export_type([bytes32/0]). -opaque bytes32() :: {bytes32, bitstring()}. -spec from_bit_array(bitstring()) -> {ok, bytes32()} | {error, binary()}. from_bit_array(Bytes32) -> gleam@bool:guard( begin _pipe = Bytes32, erlang:byte_size(_pipe) end /= 32, {error, <<"Incorrect length"/utf8>>}, fun() -> {ok, {bytes32, Bytes32}} end ). -spec decoder(gleam@dynamic:dynamic_()) -> {ok, bytes32()} | {error, list(gleam@dynamic:decode_error())}. decoder(Value) -> gleam@result:'try'( gleam@dynamic:bit_array(Value), fun(Str) -> _pipe = from_bit_array(Str), gleam@result:map_error(_pipe, fun(_) -> [] end) end ). -spec to_bit_array(bytes32()) -> bitstring(). to_bit_array(Bytes32) -> {bytes32, Bytes32@1} = Bytes32, Bytes32@1.