| Crates.io | allora-macros |
| lib.rs | allora-macros |
| version | 0.0.2 |
| created_at | 2025-11-26 04:27:48.06061+00 |
| updated_at | 2025-11-26 16:58:21.570356+00 |
| description | Procedural macros for Allora (#[service]) to register service activators via inventory. |
| homepage | https://github.com/fialucci/allora |
| repository | https://github.com/fialucci/allora |
| max_upload_size | |
| id | 1950932 |
| size | 12,086 |
Procedural macros for the Allora integration library.
allora-macros provides proc-macros that reduce boilerplate when defining services and registering them with the
Allora runtime inventory.
Most users access these macros via the top-level allora crate (for example, use allora::service;). This crate is
primarily useful if you need to depend on the macros without pulling in the full facade, or if you are extending
Allora itself.
allora-macros?This crate contains the procedural macros used by Allora to:
It is tightly coupled to Allora’s types and traits. It is not intended as a general-purpose macro toolbox.
You typically don’t need to depend on allora-macros directly. Prefer the allora facade crate, which re-exports the
macros you need.
Reach for allora-macros directly only when:
allora facadeApplication code should usually use:
use allora::service; // re-export from the facade crate
Currently this crate exposes one primary attribute macro:
#[service]Attribute macro for registering a service implementation with the Allora runtime inventory.
impl block for your service type (not a trait impl)ref-name values can refer to your type#[service(name = "custom_name")] – explicit identifier; must match the YAML ref-name#[service] – omit name to default to the type name with whitespace removedConstraints / validation:
impl Type { ... }), not on a trait implnew() constructor#[service]The most common usage is via the allora facade:
use allora::{service, Exchange, Result, Service};
#[derive(Clone, Debug)]
struct Greeter;
impl Greeter {
pub fn new() -> Self {
Self
}
}
// Register this type with the Allora service inventory using an explicit name
#[service(name = "greeter")]
impl Greeter {}
#[async_trait::async_trait]
impl Service for Greeter {
async fn process(&self, ex: &mut Exchange) -> Result<()> {
if let Some(name) = ex.in_msg.body_text() {
ex.in_msg.set_body_text(format!("Hello {name}"));
}
Ok(())
}
}
fn main() {}
In your YAML configuration, you can now refer to this service by ref-name: greeter.
If you omit the name = ... argument, the macro will derive the service name from the type:
use allora::{service, Service};
#[derive(Clone, Debug)]
struct MyProcessor;
impl MyProcessor {
pub fn new() -> Self {
Self
}
}
// Name will default to "MyProcessor"
#[service]
impl MyProcessor {}
fn main() {}
The derived name is currently the Rust type name with whitespace removed.
allora-macros follows the same versioning as the rest of the Allora cratesFor a higher-level introduction to Allora and its integration patterns, see the allora crate documentation.
Licensed under Apache-2.0. See the LICENSE file in the repository for details.