pub trait ModuleBuilderQueueExt {
// Required method
fn queue_store<S, F, Fut>(
&mut self,
name: &'static str,
factory: F,
) -> &mut Self
where S: QueueStore,
F: Fn(DriverContext) -> Fut + Send + Sync + 'static,
Fut: Future<Output = Result<S, BoxError>> + Send + 'static;
}Expand description
Registers queue stores on a ModuleBuilder: use navree::plugin::prelude::*; (or this trait) brings the method.
use navree_kernel::ModuleBuilder;
use navree_queue::{ModuleBuilderQueueExt, QueueStore};
use serde::Deserialize;
/// The settings of the store: `[queue.amritsar_queue]`.
#[derive(Default, Deserialize)]
#[serde(default)]
struct AmritsarSettings {
depot: String,
}
/// What a module's `register` calls: `open` builds your `QueueStore`
/// from the settings the app configured. Selected with
/// `queue.driver = "amritsar_queue"`.
fn register_store<S: QueueStore>(m: &mut ModuleBuilder, open: fn(AmritsarSettings) -> S) {
m.queue_store("amritsar_queue", move |ctx| {
let store = ctx.settings().map(open);
async move { store }
});
}Required Methods§
Sourcefn queue_store<S, F, Fut>(
&mut self,
name: &'static str,
factory: F,
) -> &mut Selfwhere
S: QueueStore,
F: Fn(DriverContext) -> Fut + Send + Sync + 'static,
Fut: Future<Output = Result<S, BoxError>> + Send + 'static,
fn queue_store<S, F, Fut>(
&mut self,
name: &'static str,
factory: F,
) -> &mut Selfwhere
S: QueueStore,
F: Fn(DriverContext) -> Fut + Send + Sync + 'static,
Fut: Future<Output = Result<S, BoxError>> + Send + 'static,
Registers a queue store under name (a lower-case letter followed by
up to 63 lower-case letters, digits or _): queue.driver = "{name}"
selects it, and factory builds it at boot from its
DriverContext, whose settings are queue.{name}.
A name that is not such a word, a built-in name (database, memory,
redis), a key of the queue section (workers) and a name two
modules register fail the boot, naming m.queue_store and the
module, also when another store is selected; config:check says the
same. A factory that fails fails the boot, naming the store and the
module. A factory’s error is shown in the boot error as written, so it
must not contain a secret from the driver’s settings.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".