paladin/config/
mod.rs

1//! Shared runtime configuration.
2//!
3//! This module introduces types to facilitate the configuration of the runtime
4//! environment.
5//!
6//! # Features:
7//! - [`Config`]: Represents the main configuration structure. It's adorned with
8//!   [`clap`] attributes to allow easy setup via command-line arguments.
9//! - [`Serializer`]: Specifies the serialization format to use.
10//! - [`Runtime`]: Enumerates the available runtime environments.
11//!
12//! # Usage:
13//! Both the orchestrator and worker binaries require these configurations since
14//! they both utilize the same [`Runtime`](crate::runtime::Runtime).
15//! The [`Config`] struct can be passed to
16//! [`Runtime::from_config`](crate::runtime::Runtime::from_config)
17//! to dynamically construct a [`Runtime`](crate::runtime::Runtime) based on the
18//! provided configuration.
19
20use clap::{Args, ValueEnum};
21
22const HELP_HEADING: &str = "Paladin options";
23
24/// Represents the main configuration structure for the runtime.
25#[derive(Args, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Default)]
26pub struct Config {
27    /// Determines the serialization format to be used.
28    #[arg(long, short, help_heading = HELP_HEADING, value_enum, default_value_t = Serializer::Postcard)]
29    pub serializer: Serializer,
30
31    /// Specifies the runtime environment to use.
32    #[arg(long, short, help_heading = HELP_HEADING, value_enum, default_value_t = Runtime::Amqp)]
33    pub runtime: Runtime,
34
35    /// Specifies the number of worker threads to spawn (in memory runtime
36    /// only).
37    #[arg(long, short, help_heading = HELP_HEADING)]
38    pub num_workers: Option<usize>,
39
40    /// Provides the URI for the AMQP broker, if the AMQP runtime is selected.
41    #[arg(long, help_heading = HELP_HEADING, env = "AMQP_URI", required_if_eq("runtime", "amqp"))]
42    pub amqp_uri: Option<String>,
43
44    /// Provides the routing key for workers to listen on, if the AMQP runtime
45    /// is used in configuration.
46    #[arg(long, help_heading = HELP_HEADING)]
47    pub task_bus_routing_key: Option<String>,
48}
49
50/// Enumerates the available serialization formats.
51#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug, ValueEnum, Default)]
52pub enum Serializer {
53    #[default]
54    Postcard,
55    Cbor,
56}
57
58/// Enumerates the available runtime environments.
59#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug, ValueEnum, Default)]
60pub enum Runtime {
61    #[default]
62    Amqp,
63    InMemory,
64}