{"id":26194265,"url":"https://github.com/active-group/quick-struct","last_synced_at":"2025-04-15T03:15:07.819Z","repository":{"id":57555605,"uuid":"194055449","full_name":"active-group/quick-struct","owner":"active-group","description":"Elixir macro to create data structures as structs.","archived":false,"fork":false,"pushed_at":"2023-07-10T14:58:07.000Z","size":15,"stargazers_count":7,"open_issues_count":0,"forks_count":0,"subscribers_count":15,"default_branch":"master","last_synced_at":"2025-04-15T03:14:58.668Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/active-group.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-06-27T08:31:20.000Z","updated_at":"2024-03-05T21:02:12.000Z","dependencies_parsed_at":"2022-09-10T17:01:49.359Z","dependency_job_id":null,"html_url":"https://github.com/active-group/quick-struct","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/active-group%2Fquick-struct","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/active-group%2Fquick-struct/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/active-group%2Fquick-struct/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/active-group%2Fquick-struct/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/active-group","download_url":"https://codeload.github.com/active-group/quick-struct/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248997080,"owners_count":21195799,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-03-12T01:55:59.283Z","updated_at":"2025-04-15T03:15:07.803Z","avatar_url":"https://github.com/active-group.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# QuickStruct [![Build Status](https://travis-ci.org/active-group/quick-struct.svg?branch=master)](https://travis-ci.org/active-group/quick-struct) [![Hex pm](http://img.shields.io/hexpm/v/quick_struct.svg?style=flat)](https://hex.pm/packages/quick_struct)\n\nMacro to create data structures as structs with less boilerplate.\n\n## Installation\n\nFirst, add QuickStruct to your `mix.exs` dependencies:\n\n```elixir\ndef deps do\n  [{:quick_struct, \"~\u003e 0.1\"}]\nend\n```\n\nand run `$ mix deps.get`.\n\n## Usage\n\n```elixir\ndefmodule User do\n  use QuickStruct, [firstname: String.t, name: String.t]\nend\n```\n\nNow you can use `User.t` in `@type` and `@spec` declarations. To create\ninstances of your data structure, use one of the following options:\n```elixir\niex(3)\u003e User.make(\"Jon\", \"Adams\")\n%User{firstname: \"Jon\", name: \"Adams\"}\niex(4)\u003e User.make([name: \"Adams\", firstname: \"Jon\"])\n%User{firstname: \"Jon\", name: \"Adams\"}\niex(5)\u003e %User{name: \"Adams\", firstname: \"Jon\"}\n%User{firstname: \"Jon\", name: \"Adams\"}\n```\n\nYou can also define a struct without types, for instance:\n```elixir\ndefmodule QuickStructTest.Pair do\n  use QuickStruct, [:first, :second]\nend\n```\n\n### Resulting code\n\nThe QuickStruct macro is a very shorthand option to define a struct, a\ndata type and enforce all fields. The `User`-struct is equivalent to:\n```elixir\n@enforce_keys [:firstname, :name]\ndefstruct [:firstname, :name]\n@type t :: %User{firstname: String.t, name: String.t}\n```\n\nThe macro also provides `make`-functions as constructors and other functions, see [QuickStruct](https://hexdocs.pm/quick_struct/QuickStruct.html) for further documentation. The generated `make`-functions for the `User`-struct are equivalent to:\n```elixir\n@spec make(String.t, String.t) :: User.t\ndef make(firstname, name) do\n  %User{firstname: firstname, name: name}\nend\n\n@spec make([firstname: String.t, name: String.t]) :: User.t\ndef make(fields) do\n  Kernel.struct!(User, fields)\nend\n```\n\n### Generating predicates\n\nThe optional argument `:predicate` can be used to generate a predicate for the struct:\n\n```elixir\ndefmodule UserWithPredicate do\n  use QuickStruct, [firstname: String.t, name: String.t], predicate: :user?\nend\n```\n\n```elixir\niex\u003e user = User.make(\"Jon\", \"Adams\")\n%User{firstname: \"Jon\", name: \"Adams\"}\niex\u003e User.user?(user)\ntrue\niex\u003e User.user?(non_user_struct)\nfalse\niex\u003e User.user?(1)\nfalse\n```\n\n\n### Creating modules and structs\n\nIf you need plenty of different data structures, you can use\n```elixir\nrequire QuickStruct\nQuickStruct.define_module(User, [firstname: String.t, name: String.t])\nQuickStruct.define_module(Pair, [:first, :second])\n```\nto create a module and the corresponding struct. So this is shorthand for:\n\n```elixir\ndefmodule User do\n  use QuickStruct, [firstname: String.t, name: String.t]\nend\ndefmodule Pair do\n  use QuickStruct, [:first, :second]\nend\n```\n\n## License\n\nCopyright © 2021 Active Group GmbH\n\nThis work is free. You can redistribute it and/or modify it under the\nterms of the MIT License. See the LICENSE file for more details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Factive-group%2Fquick-struct","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Factive-group%2Fquick-struct","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Factive-group%2Fquick-struct/lists"}