crux_structs v0.2.3 Crux.Structs.BitField behaviour View Source

Custom non discord api behaviour to help with bitfields of all kind.

Link to this section Summary

Types

The name of a bit flag.

All valid types that can be directly resolved into a bitfield.

t()

Represents a struct of a module implementing the Crux.Structs.BitField behaviour.

Callbacks

Add all set bits of to_add to base.

Get an integer representing all available bits set.

Get a map of t:name/0s and their corresponding bit values.

Check whether the t:resolvable/0 you have has everything set you want.

Return a t:t/0 of all bits you want but not have.

Get a list of all available t:name/0s.

Create a new t:t/0 from a t:resolvable/0.

Remove all set bits of to_remove from base.

Resolve a t:resolvable/0 into a bitfield.

Serialize a t:resolvable/0 into a list of set bit flag names.

Serialize a t:resolvable/0 into a map representing bit flag names to whether they are set.

Link to this section Types

Specs

name() :: atom()

The name of a bit flag.

Link to this type

resolvable()

View Source (since 0.2.3)

Specs

resolvable() :: t() | non_neg_integer() | name() | [resolvable()]

All valid types that can be directly resolved into a bitfield.

Specs

t() :: struct()

Represents a struct of a module implementing the Crux.Structs.BitField behaviour.

Link to this section Callbacks

Link to this callback

add(base, to_add)

View Source (since 0.2.3)

Specs

add(base :: resolvable(), to_add :: resolvable()) :: t()

Add all set bits of to_add to base.

Specs

all() :: non_neg_integer()

Get an integer representing all available bits set.

Specs

flags() :: %{required(name()) => non_neg_integer()}

Get a map of t:name/0s and their corresponding bit values.

Link to this callback

has(have, want)

View Source (since 0.2.3)

Specs

has(have :: resolvable(), want :: resolvable()) :: boolean()

Check whether the t:resolvable/0 you have has everything set you want.

Link to this callback

missing(have, want)

View Source (since 0.2.3)

Specs

missing(have :: resolvable(), want :: resolvable()) :: t()

Return a t:t/0 of all bits you want but not have.

Specs

names() :: [name()]

Get a list of all available t:name/0s.

Link to this callback

new(resolvable)

View Source (since 0.2.3)

Specs

new(resolvable()) :: t()

Create a new t:t/0 from a t:resolvable/0.

Link to this callback

remove(base, to_remove)

View Source (since 0.2.3)

Specs

remove(base :: resolvable(), to_remove :: resolvable()) :: t()

Remove all set bits of to_remove from base.

Link to this callback

resolve(resolvable)

View Source (since 0.2.3)

Specs

resolve(resolvable()) :: non_neg_integer()

Resolve a t:resolvable/0 into a bitfield.

Link to this callback

to_list(resolvable)

View Source (since 0.2.3)

Specs

to_list(resolvable()) :: [name()]

Serialize a t:resolvable/0 into a list of set bit flag names.

Link to this callback

to_map(resolvable)

View Source (since 0.2.3)

Specs

to_map(resolvable()) :: %{required(name()) => boolean()}

Serialize a t:resolvable/0 into a map representing bit flag names to whether they are set.