1 unstable release
0.0.1 | Dec 19, 2024 |
---|
#3 in #teach
116 downloads per month
10KB
86 lines
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!