accessible icon indicating copy to clipboard operation
accessible copied to clipboard

Dead-simple Access behavior for Elixir structs

Build Status Hex.pm Hex.pm

Accessible

Dead-simple Access behaviour for custom structs

Installation

Add accessible as a mix.exs dependency:

def deps do
  [
    {:accessible, "~> 0.3.0"}
  ]
end

Usage

Add use Accessible to your struct's module to enable Access behavior.

defmodule YourModule
  defstruct key: 1234, key_2: true
  
  use Accessible
  
  def your_function do
  ...
end

Your struct can now use all of the features of Access, including struct[:key] access syntax and Kernel nested get/update functions.

iex> %YourModule{}[:key]
1234