occult 0.0.1

Teach your code to use magic
Documentation
  • Coverage
  • 100%
    10 out of 10 items documented1 out of 5 items with examples
  • Size
  • Source code size: 24.11 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 2.98 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 10s Average build duration of successful builds.
  • all releases: 10s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • esmevane

Occult

Teach your code magic.

Occult gives you the ability to define your own async "magic handler" functions. A magic handler is a function that can take any number of arguments and return a future, so long as those arguments can be extracted from a single input value.

Magic handlers are popular in several parts of the rust community, such as the axum and actix-web crates, and the bevy crate. They let you split your application into two layers: what it is, and what it does. However, the implementation of these magic handlers can be tough to understand, and so they tend to be tucked away inside their respective crates.

Occult aims to make it easy to define your own magic handlers, so you can use them yourself for your own programs. It's a more general implementation of the pattern, so you can pop it into your project and make a magic handler for whatever you want without leveraging those other crates.

Dependency injection & clarity

Magic handlers are a kind of dependency injection pattern. Your handlers know what they need to work, and your extractors know how to get it from a core type. This makes it easy to model out logic but it makes it hard to trace cause and effect. It's a tradeoff, but the ergonomics of magic handlers tend to broaden the amount of people who can work on code.

It's up to you whether or not you feel as though magic handlers serve you and your team. If you have a ton of people doing work on different layers, it might be ideal. Otherwise, it might add too much extra time to debugging work!