pub trait Module:
Send
+ Sync
+ 'static {
type Config: Config + Send + 'static;
type Args: Send + 'static;
const NAME: &'static str;
// Required method
fn create<'life0, 'life1, 'async_trait>(
config: Self::Config,
args: Self::Args,
ctx: &'life0 mut Context<'life1>,
) -> Pin<Box<dyn Future<Output = Result<Self, ModuleError>> + Send + 'async_trait>>
where Self: Sized + 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
// Provided methods
fn start<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), ModuleError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait { ... }
fn drain<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), ModuleError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait { ... }
fn stop<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), ModuleError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait { ... }
fn details(&self) -> Vec<(String, String)> { ... }
}Expand description
Модуль службы: конфигурация, зависимости, фоновая работа и здоровье.
Модуль создаёт сборка инстанса, когда его секция конфигурации прочитана. Связи с другими
модулями приходят аргументом Module::create — значением типа Module::Args, который
сборка заполняет. Точки start, drain и stop вызываются не более одного раза каждая;
ошибка или паника в одной точке не мешает остановить остальные модули.
Модулем владеет инстанс; зависимые модули получают его по ссылке, поэтому делиться можно тем,
что доступно через &self.
Required Associated Constants§
Required Associated Types§
Sourcetype Config: Config + Send + 'static
type Config: Config + Send + 'static
Секция конфигурации модуля. NoSettings — у модуля нет настроек.
Required Methods§
Sourcefn create<'life0, 'life1, 'async_trait>(
config: Self::Config,
args: Self::Args,
ctx: &'life0 mut Context<'life1>,
) -> Pin<Box<dyn Future<Output = Result<Self, ModuleError>> + Send + 'async_trait>>where
Self: Sized + 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn create<'life0, 'life1, 'async_trait>(
config: Self::Config,
args: Self::Args,
ctx: &'life0 mut Context<'life1>,
) -> Pin<Box<dyn Future<Output = Result<Self, ModuleError>> + Send + 'async_trait>>where
Self: Sized + 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Создать модуль. Зависимости регистрируются через ctx, состояние — дескриптором здоровья.
Provided Methods§
Sourcefn start<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), ModuleError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn start<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), ModuleError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Завести фоновую работу. Вызывается после запуска слушателей, пока инстанс принимает работу.
Sourcefn drain<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), ModuleError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn drain<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), ModuleError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Перестать брать новое и завершить текущее. Вызывается при остановке под общим таймаутом дренажа; токен модуля ещё не отменён. Ошибка записывается в журнал и остановку не прерывает.
Sourcefn stop<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), ModuleError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn stop<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), ModuleError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Освободить ресурсы. Вызывается при остановке после дренажа и отмены токена модуля, в порядке, обратном порядку сборки. Ошибка записывается в журнал и остановку не прерывает.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".