12 releases

0.3.6 Nov 21, 2022
0.3.4 Nov 3, 2022
0.3.3 Oct 31, 2022
0.3.0 Sep 20, 2022

#1420 in Procedural macros

Download history 11/week @ 2024-02-12 6/week @ 2024-02-19 43/week @ 2024-02-26 7/week @ 2024-03-04 15/week @ 2024-03-11 7/week @ 2024-03-18 20/week @ 2024-03-25

52 downloads per month
Used in 6 crates (3 directly)

MIT license

1MB
23K SLoC

COSMIC MACROS

cosmic-macros is one of the packages that compose THE COSMIC INITIATIVE a WebAssembly orchestration framework.

DirectedHandler

Derive the DirectedHandler to receive Waves:

#[derive(DirectedHandler)]
pub struct MyHandler {
  logger: PointLogger
}

ROUTES

Flag one and only one impl with #[routes] and annotate functions functions with #route[()] in order to select messages:

#[routes]
impl MyHandler {
   #[route("Ext<MyNameIs>")]
   pub async fn hello(&self, ctx: InCtx<'_, Text>) -> Result<String, UniErr> {
     Ok(format!("Hello, {}", ctx.input.to_string()))
   }
}

FULL EXAMPLE

use cosmic_space::err::UniErr;
use cosmic_space::hyper::HyperSubstance;
use cosmic_space::log::PointLogger;
use cosmic_space::substance::Substance;
use cosmic_space::substance::Substance::Text;
use cosmic_space::wave::core::ReflectedCore;
use cosmic_space::wave::exchange::InCtx;

#[derive(DirectedHandler)]
pub struct MyHandler {
  logger: PointLogger
}

#[routes]
impl MyHandler {
   /// the route attribute captures an ExtMethod implementing a custom `MyNameIs`
   /// notice that the InCtx will accept any valid cosmic_space::substance::Substance
   #[route("Ext<MyNameIs>")]
   pub async fn hello(&self, ctx: InCtx<'_, Text>) -> Result<String, UniErr> {
     /// also we can return any Substance in our Reflected wave
     Ok(format!("Hello, {}", ctx.input.to_string()))
   }

   /// if the function returns nothing then an Empty Ok Reflected will be returned unless
   /// the wave type is `Wave<Signal>`
   #[route("Ext<Bye>")]
   pub async fn bye(&self, ctx: InCtx<'_,()>) {
     self.logger.info("funny that! He left without saying a word!");
   }
}

Dependencies

~12–22MB
~314K SLoC