Trait GlobalWithoutConfig

Source
pub trait GlobalWithoutConfig:
    Send
    + Sync
    + 'static {
    // Required method
    fn init() -> impl Future<Output = Result<Arc<Self>>> + Send;

    // Provided methods
    fn tokio_runtime() -> Runtime { ... }
    fn on_services_start(
        self: &Arc<Self>,
    ) -> impl Future<Output = Result<()>> + Send { ... }
    fn on_service_exit(
        self: &Arc<Self>,
        name: &'static str,
        result: Result<()>,
    ) -> impl Future<Output = Result<()>> + Send { ... }
    fn on_exit(
        self: &Arc<Self>,
        result: Result<()>,
    ) -> impl Future<Output = Result<()>> + Send { ... }
}
Expand description

Simplified version of Global.

Implementing this trait will automatically implement Global for your type. This trait is intended to be used when you don’t need a config for your global.

Refer to Global for details.

Required Methods§

Source

fn init() -> impl Future<Output = Result<Arc<Self>>> + Send

Initialize the global.

Called to initialize the global. Returning an error from this function will cause the process to immediately exit without calling on_exit first.

Provided Methods§

Source

fn tokio_runtime() -> Runtime

Builds the tokio runtime for the process.

If not overridden, a default runtime builder is used to build the runtime. It uses the following environment variables:

  • TOKIO_WORKER_THREADS: Number of worker threads to use. If 1, a current thread runtime is used.

    See [tokio::runtime::Builder::worker_threads] for details.

  • TOKIO_MAX_BLOCKING_THREADS: Maximum number of blocking threads.

    See [tokio::runtime::Builder::max_blocking_threads] for details.

  • TOKIO_DISABLE_TIME: If true disables time.

    See [tokio::runtime::Builder::enable_time] for details.

  • TOKIO_DISABLE_IO: If true disables IO.

    See [tokio::runtime::Builder::enable_io] for details.

  • TOKIO_THREAD_STACK_SIZE: Thread stack size.

    See [tokio::runtime::Builder::thread_stack_size] for details.

  • TOKIO_GLOBAL_QUEUE_INTERVAL: Global queue interval.

    See [tokio::runtime::Builder::global_queue_interval] for details.

  • TOKIO_EVENT_INTERVAL: Event interval.

    See [tokio::runtime::Builder::event_interval] for details.

  • TOKIO_MAX_IO_EVENTS_PER_TICK: Maximum IO events per tick.

    See [tokio::runtime::Builder::max_io_events_per_tick] for details.

Source

fn on_services_start( self: &Arc<Self>, ) -> impl Future<Output = Result<()>> + Send

Called right before all services start.

Returning an error from this function will prevent any service from starting and on_exit will be called with the result of this function.

Source

fn on_service_exit( self: &Arc<Self>, name: &'static str, result: Result<()>, ) -> impl Future<Output = Result<()>> + Send

Called after a service exits.

name is the name of the service that exited and result is the result the service exited with. Returning an error from this function will stop all currently running services and on_exit will be called with the result of this function.

Source

fn on_exit( self: &Arc<Self>, result: Result<()>, ) -> impl Future<Output = Result<()>> + Send

Called after the shutdown is complete, right before exiting the process.

result is Err when the process exits due to an error in one of the services or handler functions, otherwise Ok(()).

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§