Skip to main content

hyperlane

Attribute Macro hyperlane 

Source
#[hyperlane]
Expand description

Creates a new instance of a specified type with a given variable name.

This attribute macro generates an instance initialization at the beginning of the function.

ยงUsage

use hyperlane::*;
use hyperlane_macros::*;

#[hyperlane(server: Server)]
#[hyperlane(server_config: ServerConfig)]
#[tokio::main]
async fn main() {
    server_config.set_nodelay(Some(false));
    server.server_config(server_config);
    let server_hook: ServerControlHook = server.run().await.unwrap_or_default();
    server_hook.wait().await;
}

Using in impl block method:

use hyperlane::*;
use hyperlane_macros::*;

struct ServerInitializer;

impl ServerInitializer {
    #[hyperlane(server: Server)]
    #[hyperlane(server_config: ServerConfig)]
    async fn initialize_server_1() -> Server {
        server
    }

    #[hyperlane(server: Server)]
    #[hyperlane(server_config: ServerConfig)]
    async fn initialize_server_2(self) -> Server {
        server
    }

    #[hyperlane(server: Server)]
    #[hyperlane(server_config: ServerConfig)]
    async fn initialize_server_3(&self) -> Server {
        server
    }
}

The macro accepts a variable_name: Type pair. The variable will be available as an instance of the specified type in the function scope.