Crate scuffle_bootstrap

Source
Expand description

A utility crate for creating binaries.

Refer to Global, Service, and main for more information.

See the changelog for a full release history.

§Feature flags

  • docs — Enables changelog and documentation of feature flags

§Usage

use std::sync::Arc;

/// Our global state
struct Global;

// Required by the signal service
impl scuffle_signal::SignalConfig for Global {}

impl scuffle_bootstrap::global::GlobalWithoutConfig for Global {
    async fn init() -> anyhow::Result<Arc<Self>> {
        Ok(Arc::new(Self))
    }
}

/// Our own custom service
struct MySvc;

impl scuffle_bootstrap::service::Service<Global> for MySvc {
    async fn run(self, global: Arc<Global>, ctx: scuffle_context::Context) -> anyhow::Result<()> {
        println!("running");

        // Do some work here

        // Wait for the context to be cacelled by the signal service
        ctx.done().await;
        Ok(())
    }
}

// This generates the main function which runs all the services
scuffle_bootstrap::main! {
    Global {
        scuffle_signal::SignalSvc,
        MySvc,
    }
}

§License

This project is licensed under the MIT or Apache-2.0 license. You can choose between one of them if you use this work.

SPDX-License-Identifier: MIT OR Apache-2.0

Modules§

config
Config parsing.
global
Global state for the application.
service
Service types.
changelog
Changelogs generated by [scuffle_changelog]

Re-exports§

pub use config::ConfigParser;
pub use global::Global;
pub use global::GlobalWithoutConfig;
pub use service::Service;

Macros§

main
This macro is used to generate the main function for a given global type and service types. It will run all the services in parallel and wait for them to finish before exiting.