Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Processor settings

As you saw in the cargo-prosa chapter, every processor has a configuration object attached to it. You'll specify your processor settings object when you create your processor in the next chapter.

Settings is the top-level configuration object, while ProcSettings is specific to processors.

Creation

To create a processor settings, declare a struct and use the proc_settings macro. This macro adds necessary members to your struct and implements the ProcSettings trait for you.

From these additional members, you will be able to obtain your adapter configuration and processor restart policy.

You can specify them as configurations for your processor like this:

proc:
    adaptor_config_path: /etc/adaptor_path.yaml
    proc_restart_duration_period: 50
    proc_max_restart_period: 300
    my_param: "test"

And declare your settings like this in Rust:

use serde::{Deserialize, Serialize};

#[proc_settings]
#[derive(Debug, Deserialize, Serialize)]
pub struct MySettings {
    my_param: String,
}

Implementing Default

Since the proc_settings macro adds fields to your struct, it can be tricky to manually implement a default value. Fortunately, the macro also supports a custom Default implementation that incorporates all required fields:

#[proc_settings]
impl Default for MySettings {
    fn default() -> Self {
        MySettings {
            my_param: "default param".into(),
        }
    }
}

By implementing Default for your settings, you can then create a new function that uses default parameters, for example:

impl MySettings {
    pub fn new(my_param: String) -> MySettings {
        MySettings {
            my_param,
            ..Default::default()
        }
    }
}