https://github.com/jw3126/structhelpers.jl
Automate common struct definition boilerplate
https://github.com/jw3126/structhelpers.jl
julia struct
Last synced: 9 months ago
JSON representation
Automate common struct definition boilerplate
- Host: GitHub
- URL: https://github.com/jw3126/structhelpers.jl
- Owner: jw3126
- License: mit
- Created: 2021-06-21T08:59:11.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2025-02-04T12:19:44.000Z (11 months ago)
- Last Synced: 2025-04-04T22:33:55.935Z (9 months ago)
- Topics: julia, struct
- Language: Julia
- Homepage:
- Size: 154 KB
- Stars: 16
- Watchers: 3
- Forks: 1
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# StructHelpers
[](https://jw3126.github.io/StructHelpers.jl/stable)
[](https://jw3126.github.io/StructHelpers.jl/dev)
[](https://github.com/jw3126/StructHelpers.jl/actions)
[](https://codecov.io/gh/jw3126/StructHelpers.jl)
Sometimes defining a new struct is accompanied by a bit of boilerplate. For instance the default definition of `Base.hash` is by object id. Often a `hash` that is based on the object struture is preferable however. Similar for `==`.
StructHelpers aims to simplify the boilerplate required for such common tweaks.
# Usage
```julia
struct S
a
b
end
@batteries S
@batteries S hash=false # don't overload `Base.hash`
@batteries S kwconstructor=true # add a keyword constructor
```
For all supported options and defaults, consult the docstring:
```julia
julia>?@batteries
```
# Alternatives
* [AutoHashEquals](https://github.com/andrewcooke/AutoHashEquals.jl) requires annotating the struct definition. This can be inconvenient if you want to annotate the definition with another macro as well.
* [StructEquality](https://github.com/jolin-io/StructEquality.jl) is similar to this package.