Skip to content

A named bitmask for Elixir, similar to bitmask enums in other languages

License

Notifications You must be signed in to change notification settings

JayPeet/bitmask

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Bitmask

Hex.pm Hex Docs

A bitmask implementation for elixir, with optional Ecto support.

Usage

Define your bitmask

defmodule MyBitmask do
  use Bitmask, [
    :flag_1,
    :flag_2,
    :flag_3,
    :flag_4,
  ]
end

Create your bitmask

iex> bitmask = MyBitmask.atom_flags_to_bitmask([:flag_1, :flag_3])
%MyBitmask{bitmask: 5, flags: [:flag_1, :flag_3]}

Check if we have a flag

iex> MyBitmask.has_flag(bitmask, :flag_1])
true

Store it in an Ecto schema

defmodule SomeEctoSchema do
  use Ecto.Schema
  schema "bitmasks" do
    field :my_bitmask, MyBitmask
  end
end

See the docs for more info. Issues / PRs / Feedback welcome.

About

A named bitmask for Elixir, similar to bitmask enums in other languages

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages