use std::marker::PhantomData;
use serde::Serialize;
use crate::codec::Codec;
#[cfg(any(feature = "json", feature = "cbor", feature = "msgpack"))]
use crate::codec::DefaultCodec;
#[cfg(any(feature = "json", feature = "cbor", feature = "msgpack"))]
use crate::Publisher;
use crate::{
BatchSubscriber, Broker, BuildContext, Connected, DefaultPublish, PublishPolicy, Subscriber,
SubscriptionSource,
};
use crate::runtime::SliceHandler;
use crate::runtime::batch::BatchDef;
use crate::runtime::batch_inject::{BatchInjectCall, BatchInjectDef};
use crate::runtime::batch_publishing::BatchPublishingCall;
use crate::runtime::handler::Handler;
use crate::runtime::inject::{FromStartup, InjectCall, InjectDef, InjectHandler};
use crate::runtime::input::{DecodeWith, InputKind, RawBytes};
use crate::runtime::middleware::Layer;
#[cfg(any(feature = "json", feature = "cbor", feature = "msgpack"))]
use crate::runtime::publish::TypedPublisher;
use crate::runtime::publish::{PublishPipeline, ReplyPublisher};
use crate::runtime::publishing::{PublishingCall, PublishingHandler, ReplySink};
use crate::runtime::subscriber_def::SubscriberDef;
use crate::runtime::typed::Typed;
use super::scope::BrokerScope;
pub trait IncludeDef {
type Form;
}
pub mod forms {
#[derive(Debug, Clone, Copy)]
pub struct Subscribing;
#[derive(Debug, Clone, Copy)]
pub struct RawSubscribing;
#[derive(Debug, Clone, Copy)]
pub struct RawReply;
#[derive(Debug, Clone, Copy)]
pub struct Publishing;
#[derive(Debug, Clone, Copy)]
pub struct Out;
#[derive(Debug, Clone, Copy)]
pub struct Seek;
#[derive(Debug, Clone, Copy)]
pub struct PublishingOut;
#[derive(Debug, Clone, Copy)]
pub struct RawReplyOut;
#[derive(Debug, Clone, Copy)]
pub struct Batch;
#[derive(Debug, Clone, Copy)]
pub struct BatchPublishing;
#[derive(Debug, Clone, Copy)]
pub struct BatchOut;
#[derive(Debug, Clone, Copy)]
pub struct BatchSeek;
#[derive(Debug, Clone, Copy)]
pub struct BatchPublishingOut;
}
#[doc(hidden)]
pub trait IncludeMount<'s, B: Broker, Layers, C, State, Pipeline, Def> {
type Out;
fn begin(def: Def, scope: &'s mut BrokerScope<B, Layers, C, State, Pipeline>) -> Self::Out;
}
impl<B: Broker + 'static, Layers, C, State, Pipeline> BrokerScope<B, Layers, C, State, Pipeline> {
pub fn include<'s, Def>(
&'s mut self,
def: Def,
) -> <Def::Form as IncludeMount<'s, B, Layers, C, State, Pipeline, Def>>::Out
where
Def: IncludeDef,
Def::Form: IncludeMount<'s, B, Layers, C, State, Pipeline, Def>,
{
<Def::Form as IncludeMount<'s, B, Layers, C, State, Pipeline, Def>>::begin(def, self)
}
pub fn include_batch<'s, Def>(
&'s mut self,
def: Def,
) -> <Def::Form as IncludeMount<'s, B, Layers, C, State, Pipeline, Def>>::Out
where
Def: IncludeDef,
Def::Form: IncludeMount<'s, B, Layers, C, State, Pipeline, Def>,
{
<Def::Form as IncludeMount<'s, B, Layers, C, State, Pipeline, Def>>::begin(def, self)
}
}
#[doc(hidden)]
pub trait ScopeCodec {
type Codec: Codec + Clone + Send + Sync + 'static;
fn scope_codec(&self) -> Self::Codec;
}
#[cfg(any(feature = "json", feature = "cbor", feature = "msgpack"))]
impl ScopeCodec for () {
type Codec = DefaultCodec;
fn scope_codec(&self) -> Self::Codec {
DefaultCodec::default()
}
}
impl<C: Codec + Clone + Send + Sync + 'static> ScopeCodec for C {
type Codec = C;
fn scope_codec(&self) -> Self::Codec {
self.clone()
}
}
impl<'s, B, Layers, C, State, Pipeline, Def> IncludeMount<'s, B, Layers, C, State, Pipeline, Def>
for forms::Subscribing
where
B: Broker + 'static,
C: ScopeCodec,
Def: SubscriberDef,
Def::Source: SubscriptionSource<Connected<B>> + Send + 'static,
<Def::Source as SubscriptionSource<Connected<B>>>::Subscriber: Send + 'static,
<<Def::Source as SubscriptionSource<Connected<B>>>::Subscriber as Subscriber>::Message: 'static,
Def::Input: DecodeWith<<C as ScopeCodec>::Codec>,
Def::Handler: 'static,
Def::Context: BuildContext<
<<Def::Source as SubscriptionSource<Connected<B>>>::Subscriber as Subscriber>::Message,
> + Send
+ 'static,
State: Send + Sync + 'static,
Layers: Layer<
Typed<
<<Def::Source as SubscriptionSource<Connected<B>>>::Subscriber as Subscriber>::Message,
Def::Input,
C::Codec,
Def::Handler,
>,
>,
Layers::Handler: Handler<
<<Def::Source as SubscriptionSource<Connected<B>>>::Subscriber as Subscriber>::Message,
Def::Context,
State,
> + 'static,
{
type Out = ();
fn begin(def: Def, scope: &'s mut BrokerScope<B, Layers, C, State, Pipeline>) {
let source = def.source();
let codec = scope.codec.scope_codec();
scope.mount_subscriber(source, def, codec);
}
}
impl<'s, B, Layers, C, State, Pipeline, Def> IncludeMount<'s, B, Layers, C, State, Pipeline, Def>
for forms::RawSubscribing
where
B: Broker + 'static,
Def: SubscriberDef<Input = RawBytes>,
Def::Source: SubscriptionSource<Connected<B>> + Send + 'static,
<Def::Source as SubscriptionSource<Connected<B>>>::Subscriber: Send + 'static,
<<Def::Source as SubscriptionSource<Connected<B>>>::Subscriber as Subscriber>::Message: 'static,
Def::Handler: 'static,
Def::Context: BuildContext<
<<Def::Source as SubscriptionSource<Connected<B>>>::Subscriber as Subscriber>::Message,
> + Send
+ 'static,
State: Send + Sync + 'static,
Layers: Layer<
Typed<
<<Def::Source as SubscriptionSource<Connected<B>>>::Subscriber as Subscriber>::Message,
RawBytes,
(),
Def::Handler,
>,
>,
Layers::Handler: Handler<
<<Def::Source as SubscriptionSource<Connected<B>>>::Subscriber as Subscriber>::Message,
Def::Context,
State,
> + 'static,
{
type Out = ();
fn begin(def: Def, scope: &'s mut BrokerScope<B, Layers, C, State, Pipeline>) {
let source = def.source();
scope.mount_subscriber(source, def, ());
}
}
impl<'s, B, Layers, C, State, Pipeline, Def> IncludeMount<'s, B, Layers, C, State, Pipeline, Def>
for forms::Seek
where
B: Broker + 'static,
C: ScopeCodec,
Def: InjectCall<State> + 'static,
Def::Source: SubscriptionSource<Connected<B>> + Send + 'static,
<Def::Source as SubscriptionSource<Connected<B>>>::Subscriber: Sync + Send + 'static,
<<Def::Source as SubscriptionSource<Connected<B>>>::Subscriber as Subscriber>::Message:
Send + Sync + 'static,
Def::Input: DecodeWith<<C as ScopeCodec>::Codec>,
Def::Context: BuildContext<
<<Def::Source as SubscriptionSource<Connected<B>>>::Subscriber as Subscriber>::Message,
> + Send
+ Sync
+ 'static,
Def::Injections: FromStartup<B, <Def::Source as SubscriptionSource<Connected<B>>>::Subscriber, ()>
+ Send
+ Sync
+ 'static,
State: Send + Sync + 'static,
Layers: Layer<InjectHandler<Def, <C as ScopeCodec>::Codec>> + Clone + Send + 'static,
Layers::Handler: Handler<
<<Def::Source as SubscriptionSource<Connected<B>>>::Subscriber as Subscriber>::Message,
Def::Context,
State,
> + 'static,
{
type Out = ();
fn begin(def: Def, scope: &'s mut BrokerScope<B, Layers, C, State, Pipeline>) {
let source = def.source();
scope.mount_inject(source, def, ());
}
}
impl<'s, B, Layers, C, State, Pipeline, Def> IncludeMount<'s, B, Layers, C, State, Pipeline, Def>
for forms::Batch
where
B: Broker + 'static,
C: ScopeCodec,
Def: BatchDef,
Def::Source: SubscriptionSource<Connected<B>> + Send + 'static,
<Def::Source as SubscriptionSource<Connected<B>>>::Subscriber: BatchSubscriber + Send + 'static,
Def::Input: DecodeWith<<C as ScopeCodec>::Codec>,
Def::Handler: SliceHandler<<Def::Input as InputKind>::Owned, State> + 'static,
State: Send + Sync + 'static,
{
type Out = ();
fn begin(def: Def, scope: &'s mut BrokerScope<B, Layers, C, State, Pipeline>) {
let source = def.source();
let codec = scope.codec.scope_codec();
scope.mount_batch(source, def, codec);
}
}
#[doc(hidden)]
#[derive(Debug, Clone, Copy, Default)]
pub struct DefaultReply;
#[doc(hidden)]
#[derive(Debug, Clone, Copy, Default)]
pub struct DefaultBareReply;
#[doc(hidden)]
#[derive(Debug)]
pub struct WithSource<Source>(Source);
#[doc(hidden)]
#[derive(Debug, Clone, Copy, Default)]
pub struct MissingOut;
#[doc(hidden)]
#[derive(Debug, Clone, Copy)]
pub struct PublishMount;
#[doc(hidden)]
#[derive(Debug, Clone, Copy)]
pub struct InjectMount;
#[doc(hidden)]
#[derive(Debug, Clone, Copy)]
pub struct BatchPublishMount;
#[doc(hidden)]
#[derive(Debug, Clone, Copy)]
pub struct BatchInjectMount;
#[doc(hidden)]
#[derive(Debug, Clone, Copy)]
pub struct PublishInjectMount;
#[doc(hidden)]
#[derive(Debug, Clone, Copy)]
pub struct BatchPublishInjectMount;
#[doc(hidden)]
pub trait CommitVia<Mount, B: Broker, Layers, C, State, Pipeline, Def>: Sized {
fn commit(self, def: Def, scope: &mut BrokerScope<B, Layers, C, State, Pipeline>);
}
impl<Mount, B, Layers, C, State, Pipeline, Def> CommitVia<Mount, B, Layers, C, State, Pipeline, Def>
for MissingOut
where
B: Broker + 'static,
{
fn commit(self, _def: Def, _scope: &mut BrokerScope<B, Layers, C, State, Pipeline>) {
panic!(
"an Out handler was included without a publisher source: chain \
.publisher(<policy or bound token>) on the include call"
);
}
}
impl<Mount, B, Layers, C, State, Pipeline, Def, Reply>
CommitVia<Mount, B, Layers, C, State, Pipeline, Def> for (Reply, MissingOut)
where
B: Broker + 'static,
{
fn commit(self, _def: Def, _scope: &mut BrokerScope<B, Layers, C, State, Pipeline>) {
panic!(
"a publishing handler with an Out parameter was included without its publisher \
source: chain .out(<policy or bound token>) on the include call"
);
}
}
#[cfg(any(feature = "json", feature = "cbor", feature = "msgpack"))]
impl<B, Layers, C, State, Pipeline, Def> CommitVia<PublishMount, B, Layers, C, State, Pipeline, Def>
for DefaultReply
where
B: Broker + 'static,
B::Connected: DefaultPublish,
WithSource<TypedPublisher<<B::Connected as DefaultPublish>::Policy, DefaultCodec>>:
CommitVia<PublishMount, B, Layers, C, State, Pipeline, Def>,
{
fn commit(self, def: Def, scope: &mut BrokerScope<B, Layers, C, State, Pipeline>) {
CommitVia::commit(
WithSource(TypedPublisher::new(
<B::Connected as DefaultPublish>::Policy::default(),
)),
def,
scope,
);
}
}
impl<B, Layers, C, State, Pipeline, Def> CommitVia<PublishMount, B, Layers, C, State, Pipeline, Def>
for DefaultBareReply
where
B: Broker + 'static,
B::Connected: DefaultPublish,
WithSource<<B::Connected as DefaultPublish>::Policy>:
CommitVia<PublishMount, B, Layers, C, State, Pipeline, Def>,
{
fn commit(self, def: Def, scope: &mut BrokerScope<B, Layers, C, State, Pipeline>) {
CommitVia::commit(
WithSource(<B::Connected as DefaultPublish>::Policy::default()),
def,
scope,
);
}
}
impl<B, Layers, C, State, Pipeline, Def, Source>
CommitVia<PublishMount, B, Layers, C, State, Pipeline, Def> for WithSource<Source>
where
B: Broker + 'static,
C: ScopeCodec,
Def: PublishingCall<State> + 'static,
Def::Source: SubscriptionSource<Connected<B>> + Send + 'static,
<Def::Source as SubscriptionSource<Connected<B>>>::Subscriber: Sync + Send + 'static,
<<Def::Source as SubscriptionSource<Connected<B>>>::Subscriber as Subscriber>::Message:
Send + Sync + 'static,
Def::Input: DecodeWith<<C as ScopeCodec>::Codec>,
Def::Injections: FromStartup<B, <Def::Source as SubscriptionSource<Connected<B>>>::Subscriber, ()>
+ Send
+ Sync
+ 'static,
Def::Reply: Send + Sync + 'static,
Def::Context: BuildContext<
<<Def::Source as SubscriptionSource<Connected<B>>>::Subscriber as Subscriber>::Message,
> + Send
+ Sync
+ 'static,
Source: PublishPolicy<Connected<B>> + Send + 'static,
Source::Live: ReplySink<Def::Reply, Def::Context, Pipeline> + 'static,
Pipeline: PublishPipeline + Clone + Send + 'static,
State: Send + Sync + 'static,
Layers: Layer<PublishingHandler<Def, <C as ScopeCodec>::Codec, Source::Live, Pipeline>>
+ Clone
+ Send
+ 'static,
Layers::Handler: Handler<
<<Def::Source as SubscriptionSource<Connected<B>>>::Subscriber as Subscriber>::Message,
Def::Context,
State,
> + 'static,
{
fn commit(self, def: Def, scope: &mut BrokerScope<B, Layers, C, State, Pipeline>) {
let source = def.source();
scope.mount_publishing_source(source, def, self.0, ());
}
}
pub struct IncludeWith<'s, Mount, B, Layers, C, State, Pipeline, Def, Attachment>
where
B: Broker + 'static,
Attachment: CommitVia<Mount, B, Layers, C, State, Pipeline, Def>,
{
scope: Option<&'s mut BrokerScope<B, Layers, C, State, Pipeline>>,
parts: Option<(Def, Attachment)>,
_mount: PhantomData<Mount>,
}
pub type IncludePublishing<'s, B, Layers, C, State, Pipeline, Def, Source> =
IncludeWith<'s, PublishMount, B, Layers, C, State, Pipeline, Def, Source>;
pub type IncludeOut<'s, B, Layers, C, State, Pipeline, Def, Source> =
IncludeWith<'s, InjectMount, B, Layers, C, State, Pipeline, Def, Source>;
pub type IncludeBatchPublishing<'s, B, Layers, C, State, Pipeline, Def, Source> =
IncludeWith<'s, BatchPublishMount, B, Layers, C, State, Pipeline, Def, Source>;
pub type IncludeBatchOut<'s, B, Layers, C, State, Pipeline, Def, Source> =
IncludeWith<'s, BatchInjectMount, B, Layers, C, State, Pipeline, Def, Source>;
impl<'s, Mount, B, Layers, C, State, Pipeline, Def, Attachment>
IncludeWith<'s, Mount, B, Layers, C, State, Pipeline, Def, Attachment>
where
B: Broker + 'static,
Attachment: CommitVia<Mount, B, Layers, C, State, Pipeline, Def>,
{
pub fn publisher<NewSource>(
mut self,
source: NewSource,
) -> IncludeWith<'s, Mount, B, Layers, C, State, Pipeline, Def, WithSource<NewSource>>
where
WithSource<NewSource>: CommitVia<Mount, B, Layers, C, State, Pipeline, Def>,
{
let (def, _default) = self
.parts
.take()
.expect("builder parts are present until commit or replacement");
let scope = self
.scope
.take()
.expect("builder scope is present until commit or replacement");
IncludeWith {
scope: Some(scope),
parts: Some((def, WithSource(source))),
_mount: PhantomData,
}
}
}
impl<Mount, B, Layers, C, State, Pipeline, Def, Attachment> std::fmt::Debug
for IncludeWith<'_, Mount, B, Layers, C, State, Pipeline, Def, Attachment>
where
B: Broker + 'static,
Attachment: CommitVia<Mount, B, Layers, C, State, Pipeline, Def>,
{
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("IncludeWith").finish_non_exhaustive()
}
}
impl<Mount, B, Layers, C, State, Pipeline, Def, Attachment> Drop
for IncludeWith<'_, Mount, B, Layers, C, State, Pipeline, Def, Attachment>
where
B: Broker + 'static,
Attachment: CommitVia<Mount, B, Layers, C, State, Pipeline, Def>,
{
fn drop(&mut self) {
if let (Some((def, src)), Some(scope)) = (self.parts.take(), self.scope.take()) {
src.commit(def, scope);
}
}
}
pub struct IncludeWithOut<'s, Mount, B, Layers, C, State, Pipeline, Def, Reply, OutSource>
where
B: Broker + 'static,
(Reply, OutSource): CommitVia<Mount, B, Layers, C, State, Pipeline, Def>,
{
scope: Option<&'s mut BrokerScope<B, Layers, C, State, Pipeline>>,
parts: Option<(Def, Reply, OutSource)>,
_mount: PhantomData<Mount>,
}
pub type IncludePublishingOut<'s, B, Layers, C, State, Pipeline, Def, Reply, OutSource> =
IncludeWithOut<'s, PublishInjectMount, B, Layers, C, State, Pipeline, Def, Reply, OutSource>;
pub type IncludeBatchPublishingOut<'s, B, Layers, C, State, Pipeline, Def, Reply, OutSource> =
IncludeWithOut<
's,
BatchPublishInjectMount,
B,
Layers,
C,
State,
Pipeline,
Def,
Reply,
OutSource,
>;
impl<'s, Mount, B, Layers, C, State, Pipeline, Def, Reply, OutSource>
IncludeWithOut<'s, Mount, B, Layers, C, State, Pipeline, Def, Reply, OutSource>
where
B: Broker + 'static,
(Reply, OutSource): CommitVia<Mount, B, Layers, C, State, Pipeline, Def>,
{
pub fn publisher<NewSource>(
mut self,
source: NewSource,
) -> IncludeWithOut<
's,
Mount,
B,
Layers,
C,
State,
Pipeline,
Def,
WithSource<NewSource>,
OutSource,
>
where
(WithSource<NewSource>, OutSource): CommitVia<Mount, B, Layers, C, State, Pipeline, Def>,
{
let (def, _default, out) = self
.parts
.take()
.expect("builder parts are present until commit or replacement");
let scope = self
.scope
.take()
.expect("builder scope is present until commit or replacement");
IncludeWithOut {
scope: Some(scope),
parts: Some((def, WithSource(source), out)),
_mount: PhantomData,
}
}
pub fn out<NewSource>(
mut self,
source: NewSource,
) -> IncludeWithOut<'s, Mount, B, Layers, C, State, Pipeline, Def, Reply, WithSource<NewSource>>
where
(Reply, WithSource<NewSource>): CommitVia<Mount, B, Layers, C, State, Pipeline, Def>,
{
let (def, reply, _missing) = self
.parts
.take()
.expect("builder parts are present until commit or replacement");
let scope = self
.scope
.take()
.expect("builder scope is present until commit or replacement");
IncludeWithOut {
scope: Some(scope),
parts: Some((def, reply, WithSource(source))),
_mount: PhantomData,
}
}
}
impl<Mount, B, Layers, C, State, Pipeline, Def, Reply, OutSource> std::fmt::Debug
for IncludeWithOut<'_, Mount, B, Layers, C, State, Pipeline, Def, Reply, OutSource>
where
B: Broker + 'static,
(Reply, OutSource): CommitVia<Mount, B, Layers, C, State, Pipeline, Def>,
{
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("IncludeWithOut").finish_non_exhaustive()
}
}
impl<Mount, B, Layers, C, State, Pipeline, Def, Reply, OutSource> Drop
for IncludeWithOut<'_, Mount, B, Layers, C, State, Pipeline, Def, Reply, OutSource>
where
B: Broker + 'static,
(Reply, OutSource): CommitVia<Mount, B, Layers, C, State, Pipeline, Def>,
{
fn drop(&mut self) {
if let (Some((def, reply, out)), Some(scope)) = (self.parts.take(), self.scope.take()) {
(reply, out).commit(def, scope);
}
}
}
impl<'s, B, Layers, C, State, Pipeline, Def> IncludeMount<'s, B, Layers, C, State, Pipeline, Def>
for forms::Publishing
where
B: Broker + 'static,
Layers: 's,
C: 's,
State: 's,
Pipeline: 's,
DefaultReply: CommitVia<PublishMount, B, Layers, C, State, Pipeline, Def>,
{
type Out = IncludePublishing<'s, B, Layers, C, State, Pipeline, Def, DefaultReply>;
fn begin(def: Def, scope: &'s mut BrokerScope<B, Layers, C, State, Pipeline>) -> Self::Out {
IncludeWith {
scope: Some(scope),
parts: Some((def, DefaultReply)),
_mount: PhantomData,
}
}
}
impl<'s, B, Layers, C, State, Pipeline, Def> IncludeMount<'s, B, Layers, C, State, Pipeline, Def>
for forms::RawReply
where
B: Broker + 'static,
Layers: 's,
C: 's,
State: 's,
Pipeline: 's,
DefaultBareReply: CommitVia<PublishMount, B, Layers, C, State, Pipeline, Def>,
{
type Out = IncludePublishing<'s, B, Layers, C, State, Pipeline, Def, DefaultBareReply>;
fn begin(def: Def, scope: &'s mut BrokerScope<B, Layers, C, State, Pipeline>) -> Self::Out {
IncludeWith {
scope: Some(scope),
parts: Some((def, DefaultBareReply)),
_mount: PhantomData,
}
}
}
#[cfg(any(feature = "json", feature = "cbor", feature = "msgpack"))]
impl<B, Layers, C, State, Pipeline, Def, OutSource>
CommitVia<PublishInjectMount, B, Layers, C, State, Pipeline, Def>
for (DefaultReply, WithSource<OutSource>)
where
B: Broker + 'static,
B::Connected: DefaultPublish,
(
WithSource<TypedPublisher<<B::Connected as DefaultPublish>::Policy, DefaultCodec>>,
WithSource<OutSource>,
): CommitVia<PublishInjectMount, B, Layers, C, State, Pipeline, Def>,
{
fn commit(self, def: Def, scope: &mut BrokerScope<B, Layers, C, State, Pipeline>) {
CommitVia::commit(
(
WithSource(TypedPublisher::new(
<B::Connected as DefaultPublish>::Policy::default(),
)),
self.1,
),
def,
scope,
);
}
}
impl<B, Layers, C, State, Pipeline, Def, OutSource>
CommitVia<PublishInjectMount, B, Layers, C, State, Pipeline, Def>
for (DefaultBareReply, WithSource<OutSource>)
where
B: Broker + 'static,
B::Connected: DefaultPublish,
(
WithSource<<B::Connected as DefaultPublish>::Policy>,
WithSource<OutSource>,
): CommitVia<PublishInjectMount, B, Layers, C, State, Pipeline, Def>,
{
fn commit(self, def: Def, scope: &mut BrokerScope<B, Layers, C, State, Pipeline>) {
CommitVia::commit(
(
WithSource(<B::Connected as DefaultPublish>::Policy::default()),
self.1,
),
def,
scope,
);
}
}
impl<B, Layers, C, State, Pipeline, Def, Source, OutSource>
CommitVia<PublishInjectMount, B, Layers, C, State, Pipeline, Def>
for (WithSource<Source>, WithSource<OutSource>)
where
B: Broker + 'static,
C: ScopeCodec,
Def: PublishingCall<State> + 'static,
Def::Source: SubscriptionSource<Connected<B>> + Send + 'static,
<Def::Source as SubscriptionSource<Connected<B>>>::Subscriber: Sync + Send + 'static,
<<Def::Source as SubscriptionSource<Connected<B>>>::Subscriber as Subscriber>::Message:
Send + Sync + 'static,
Def::Input: DecodeWith<<C as ScopeCodec>::Codec>,
Def::Injections: FromStartup<B, <Def::Source as SubscriptionSource<Connected<B>>>::Subscriber, OutSource>
+ Send
+ Sync
+ 'static,
Def::Reply: Send + Sync + 'static,
Def::Context: BuildContext<
<<Def::Source as SubscriptionSource<Connected<B>>>::Subscriber as Subscriber>::Message,
> + Send
+ Sync
+ 'static,
Source: PublishPolicy<Connected<B>> + Send + 'static,
Source::Live: ReplySink<Def::Reply, Def::Context, Pipeline> + 'static,
OutSource: Send + Sync + 'static,
Pipeline: PublishPipeline + Clone + Send + 'static,
State: Send + Sync + 'static,
Layers: Layer<PublishingHandler<Def, <C as ScopeCodec>::Codec, Source::Live, Pipeline>>
+ Clone
+ Send
+ 'static,
Layers::Handler: Handler<
<<Def::Source as SubscriptionSource<Connected<B>>>::Subscriber as Subscriber>::Message,
Def::Context,
State,
> + 'static,
{
fn commit(self, def: Def, scope: &mut BrokerScope<B, Layers, C, State, Pipeline>) {
let source = def.source();
scope.mount_publishing_source(source, def, self.0.0, self.1.0);
}
}
impl<'s, B, Layers, C, State, Pipeline, Def> IncludeMount<'s, B, Layers, C, State, Pipeline, Def>
for forms::PublishingOut
where
B: Broker + 'static,
Layers: 's,
C: 's,
State: 's,
Pipeline: 's,
(DefaultReply, MissingOut): CommitVia<PublishInjectMount, B, Layers, C, State, Pipeline, Def>,
{
type Out =
IncludePublishingOut<'s, B, Layers, C, State, Pipeline, Def, DefaultReply, MissingOut>;
fn begin(def: Def, scope: &'s mut BrokerScope<B, Layers, C, State, Pipeline>) -> Self::Out {
IncludeWithOut {
scope: Some(scope),
parts: Some((def, DefaultReply, MissingOut)),
_mount: PhantomData,
}
}
}
impl<'s, B, Layers, C, State, Pipeline, Def> IncludeMount<'s, B, Layers, C, State, Pipeline, Def>
for forms::RawReplyOut
where
B: Broker + 'static,
Layers: 's,
C: 's,
State: 's,
Pipeline: 's,
(DefaultBareReply, MissingOut):
CommitVia<PublishInjectMount, B, Layers, C, State, Pipeline, Def>,
{
type Out =
IncludePublishingOut<'s, B, Layers, C, State, Pipeline, Def, DefaultBareReply, MissingOut>;
fn begin(def: Def, scope: &'s mut BrokerScope<B, Layers, C, State, Pipeline>) -> Self::Out {
IncludeWithOut {
scope: Some(scope),
parts: Some((def, DefaultBareReply, MissingOut)),
_mount: PhantomData,
}
}
}
impl<B, Layers, C, State, Pipeline, Def, Source>
CommitVia<InjectMount, B, Layers, C, State, Pipeline, Def> for WithSource<Source>
where
B: Broker + 'static,
C: ScopeCodec,
Def: InjectCall<State> + 'static,
Def::Source: SubscriptionSource<Connected<B>> + Send + 'static,
<Def::Source as SubscriptionSource<Connected<B>>>::Subscriber: Sync + Send + 'static,
<<Def::Source as SubscriptionSource<Connected<B>>>::Subscriber as Subscriber>::Message:
Send + Sync + 'static,
Def::Input: DecodeWith<<C as ScopeCodec>::Codec>,
Def::Context: BuildContext<
<<Def::Source as SubscriptionSource<Connected<B>>>::Subscriber as Subscriber>::Message,
> + Send
+ Sync
+ 'static,
Def::Injections: FromStartup<B, <Def::Source as SubscriptionSource<Connected<B>>>::Subscriber, Source>
+ Send
+ Sync
+ 'static,
Source: Send + Sync + 'static,
State: Send + Sync + 'static,
Layers: Layer<InjectHandler<Def, <C as ScopeCodec>::Codec>> + Clone + Send + 'static,
Layers::Handler: Handler<
<<Def::Source as SubscriptionSource<Connected<B>>>::Subscriber as Subscriber>::Message,
Def::Context,
State,
> + 'static,
{
fn commit(self, def: Def, scope: &mut BrokerScope<B, Layers, C, State, Pipeline>) {
let source = def.source();
scope.mount_inject(source, def, self.0);
}
}
impl<'s, B, Layers, C, State, Pipeline, Def> IncludeMount<'s, B, Layers, C, State, Pipeline, Def>
for forms::Out
where
B: Broker + 'static,
Layers: 's,
C: 's,
State: 's,
Pipeline: 's,
Def: InjectDef,
{
type Out = IncludeOut<'s, B, Layers, C, State, Pipeline, Def, MissingOut>;
fn begin(def: Def, scope: &'s mut BrokerScope<B, Layers, C, State, Pipeline>) -> Self::Out {
IncludeWith {
scope: Some(scope),
parts: Some((def, MissingOut)),
_mount: PhantomData,
}
}
}
impl<'s, B, Layers, C, State, Pipeline, Def> IncludeMount<'s, B, Layers, C, State, Pipeline, Def>
for forms::BatchSeek
where
B: Broker + 'static,
C: ScopeCodec,
Def: BatchInjectCall<State> + 'static,
Def::Source: SubscriptionSource<Connected<B>> + Send + 'static,
<Def::Source as SubscriptionSource<Connected<B>>>::Subscriber:
BatchSubscriber + Sync + Send + 'static,
<<Def::Source as SubscriptionSource<Connected<B>>>::Subscriber as Subscriber>::Message:
Send + 'static,
Def::Input: DecodeWith<<C as ScopeCodec>::Codec>,
Def::Injections: FromStartup<B, <Def::Source as SubscriptionSource<Connected<B>>>::Subscriber, ()>
+ Send
+ Sync
+ 'static,
State: Send + Sync + 'static,
{
type Out = ();
fn begin(def: Def, scope: &'s mut BrokerScope<B, Layers, C, State, Pipeline>) {
let source = def.source();
scope.mount_batch_inject(source, def, ());
}
}
impl<B, Layers, C, State, Pipeline, Def, Source>
CommitVia<BatchInjectMount, B, Layers, C, State, Pipeline, Def> for WithSource<Source>
where
B: Broker + 'static,
C: ScopeCodec,
Def: BatchInjectCall<State> + 'static,
Def::Source: SubscriptionSource<Connected<B>> + Send + 'static,
<Def::Source as SubscriptionSource<Connected<B>>>::Subscriber:
BatchSubscriber + Sync + Send + 'static,
<<Def::Source as SubscriptionSource<Connected<B>>>::Subscriber as Subscriber>::Message:
Send + 'static,
Def::Input: DecodeWith<<C as ScopeCodec>::Codec>,
Def::Injections: FromStartup<B, <Def::Source as SubscriptionSource<Connected<B>>>::Subscriber, Source>
+ Send
+ Sync
+ 'static,
Source: Send + Sync + 'static,
State: Send + Sync + 'static,
{
fn commit(self, def: Def, scope: &mut BrokerScope<B, Layers, C, State, Pipeline>) {
let source = def.source();
scope.mount_batch_inject(source, def, self.0);
}
}
impl<'s, B, Layers, C, State, Pipeline, Def> IncludeMount<'s, B, Layers, C, State, Pipeline, Def>
for forms::BatchOut
where
B: Broker + 'static,
Layers: 's,
C: 's,
State: 's,
Pipeline: 's,
Def: BatchInjectDef,
{
type Out = IncludeBatchOut<'s, B, Layers, C, State, Pipeline, Def, MissingOut>;
fn begin(def: Def, scope: &'s mut BrokerScope<B, Layers, C, State, Pipeline>) -> Self::Out {
IncludeWith {
scope: Some(scope),
parts: Some((def, MissingOut)),
_mount: PhantomData,
}
}
}
#[cfg(any(feature = "json", feature = "cbor", feature = "msgpack"))]
impl<B, Layers, C, State, Pipeline, Def>
CommitVia<BatchPublishMount, B, Layers, C, State, Pipeline, Def> for DefaultReply
where
B: Broker + 'static,
B::Connected: DefaultPublish,
C: ScopeCodec,
Def: BatchPublishingCall<State> + 'static,
Def::Source: SubscriptionSource<Connected<B>> + Send + 'static,
<Def::Source as SubscriptionSource<Connected<B>>>::Subscriber:
BatchSubscriber + Sync + Send + 'static,
<<Def::Source as SubscriptionSource<Connected<B>>>::Subscriber as Subscriber>::Message:
Send + 'static,
Def::Input: DecodeWith<<C as ScopeCodec>::Codec>,
Def::Injections: FromStartup<B, <Def::Source as SubscriptionSource<Connected<B>>>::Subscriber, ()>
+ Send
+ Sync
+ 'static,
Def::Reply: Serialize + Send + Sync + 'static,
<<B::Connected as DefaultPublish>::Policy as PublishPolicy<Connected<B>>>::Live:
Publisher + 'static,
Pipeline: PublishPipeline + Clone + Send + 'static,
State: Send + Sync + 'static,
{
fn commit(self, def: Def, scope: &mut BrokerScope<B, Layers, C, State, Pipeline>) {
let source = def.source();
let reply = TypedPublisher::new(<B::Connected as DefaultPublish>::Policy::default());
scope.mount_batch_publishing_source(source, def, reply, ());
}
}
impl<B, Layers, C, State, Pipeline, Def, Source, BatchReply>
CommitVia<BatchPublishMount, B, Layers, C, State, Pipeline, Def> for WithSource<Source>
where
B: Broker + 'static,
C: ScopeCodec,
Def: BatchPublishingCall<State> + 'static,
Def::Source: SubscriptionSource<Connected<B>> + Send + 'static,
<Def::Source as SubscriptionSource<Connected<B>>>::Subscriber:
BatchSubscriber + Sync + Send + 'static,
<<Def::Source as SubscriptionSource<Connected<B>>>::Subscriber as Subscriber>::Message:
Send + 'static,
Def::Input: DecodeWith<<C as ScopeCodec>::Codec>,
Def::Injections: FromStartup<B, <Def::Source as SubscriptionSource<Connected<B>>>::Subscriber, ()>
+ Send
+ Sync
+ 'static,
Def::Reply: Serialize + Send + Sync + 'static,
Source: PublishPolicy<Connected<B>, Live = BatchReply> + Send + 'static,
BatchReply: ReplyPublisher + 'static,
Pipeline: PublishPipeline + Clone + Send + 'static,
State: Send + Sync + 'static,
{
fn commit(self, def: Def, scope: &mut BrokerScope<B, Layers, C, State, Pipeline>) {
let source = def.source();
scope.mount_batch_publishing_source(source, def, self.0, ());
}
}
impl<'s, B, Layers, C, State, Pipeline, Def> IncludeMount<'s, B, Layers, C, State, Pipeline, Def>
for forms::BatchPublishing
where
B: Broker + 'static,
Layers: 's,
C: 's,
State: 's,
Pipeline: 's,
DefaultReply: CommitVia<BatchPublishMount, B, Layers, C, State, Pipeline, Def>,
{
type Out = IncludeBatchPublishing<'s, B, Layers, C, State, Pipeline, Def, DefaultReply>;
fn begin(def: Def, scope: &'s mut BrokerScope<B, Layers, C, State, Pipeline>) -> Self::Out {
IncludeWith {
scope: Some(scope),
parts: Some((def, DefaultReply)),
_mount: PhantomData,
}
}
}
#[cfg(any(feature = "json", feature = "cbor", feature = "msgpack"))]
impl<B, Layers, C, State, Pipeline, Def, OutSource>
CommitVia<BatchPublishInjectMount, B, Layers, C, State, Pipeline, Def>
for (DefaultReply, WithSource<OutSource>)
where
B: Broker + 'static,
B::Connected: DefaultPublish,
(
WithSource<TypedPublisher<<B::Connected as DefaultPublish>::Policy, DefaultCodec>>,
WithSource<OutSource>,
): CommitVia<BatchPublishInjectMount, B, Layers, C, State, Pipeline, Def>,
{
fn commit(self, def: Def, scope: &mut BrokerScope<B, Layers, C, State, Pipeline>) {
CommitVia::commit(
(
WithSource(TypedPublisher::new(
<B::Connected as DefaultPublish>::Policy::default(),
)),
self.1,
),
def,
scope,
);
}
}
impl<B, Layers, C, State, Pipeline, Def, Source, BatchReply, OutSource>
CommitVia<BatchPublishInjectMount, B, Layers, C, State, Pipeline, Def>
for (WithSource<Source>, WithSource<OutSource>)
where
B: Broker + 'static,
C: ScopeCodec,
Def: BatchPublishingCall<State> + 'static,
Def::Source: SubscriptionSource<Connected<B>> + Send + 'static,
<Def::Source as SubscriptionSource<Connected<B>>>::Subscriber:
BatchSubscriber + Sync + Send + 'static,
<<Def::Source as SubscriptionSource<Connected<B>>>::Subscriber as Subscriber>::Message:
Send + 'static,
Def::Input: DecodeWith<<C as ScopeCodec>::Codec>,
Def::Injections: FromStartup<B, <Def::Source as SubscriptionSource<Connected<B>>>::Subscriber, OutSource>
+ Send
+ Sync
+ 'static,
Def::Reply: Serialize + Send + Sync + 'static,
Source: PublishPolicy<Connected<B>, Live = BatchReply> + Send + 'static,
BatchReply: ReplyPublisher + 'static,
OutSource: Send + Sync + 'static,
Pipeline: PublishPipeline + Clone + Send + 'static,
State: Send + Sync + 'static,
{
fn commit(self, def: Def, scope: &mut BrokerScope<B, Layers, C, State, Pipeline>) {
let source = def.source();
scope.mount_batch_publishing_source(source, def, self.0.0, self.1.0);
}
}
impl<'s, B, Layers, C, State, Pipeline, Def> IncludeMount<'s, B, Layers, C, State, Pipeline, Def>
for forms::BatchPublishingOut
where
B: Broker + 'static,
Layers: 's,
C: 's,
State: 's,
Pipeline: 's,
(DefaultReply, MissingOut):
CommitVia<BatchPublishInjectMount, B, Layers, C, State, Pipeline, Def>,
{
type Out =
IncludeBatchPublishingOut<'s, B, Layers, C, State, Pipeline, Def, DefaultReply, MissingOut>;
fn begin(def: Def, scope: &'s mut BrokerScope<B, Layers, C, State, Pipeline>) -> Self::Out {
IncludeWithOut {
scope: Some(scope),
parts: Some((def, DefaultReply, MissingOut)),
_mount: PhantomData,
}
}
}
impl<B: Broker + 'static, Layers, C, State, Pipeline> BrokerScope<B, Layers, C, State, Pipeline> {
pub fn include_on<Source, Def>(&mut self, source: Source, def: Def)
where
Source: SubscriptionSource<Connected<B>> + Send + 'static,
Source::Subscriber: Send + 'static,
<Source::Subscriber as Subscriber>::Message: 'static,
C: ScopeCodec,
Def: SubscriberDef,
Def::Input: DecodeWith<<C as ScopeCodec>::Codec>,
Def::Handler: 'static,
Def::Context: BuildContext<<Source::Subscriber as Subscriber>::Message> + Send + 'static,
State: Send + Sync + 'static,
Layers: Layer<
Typed<<Source::Subscriber as Subscriber>::Message, Def::Input, C::Codec, Def::Handler>,
>,
Layers::Handler:
Handler<<Source::Subscriber as Subscriber>::Message, Def::Context, State> + 'static,
{
let codec = self.codec.scope_codec();
self.mount_subscriber(source, def, codec);
}
pub fn include_batch_on<Source, Def>(&mut self, source: Source, def: Def)
where
Source: SubscriptionSource<Connected<B>> + Send + 'static,
Source::Subscriber: BatchSubscriber + Send + 'static,
C: ScopeCodec,
Def: BatchDef,
Def::Input: DecodeWith<<C as ScopeCodec>::Codec>,
Def::Handler: SliceHandler<<Def::Input as InputKind>::Owned, State> + 'static,
State: Send + Sync + 'static,
{
let codec = self.codec.scope_codec();
self.mount_batch(source, def, codec);
}
}
impl<B: Broker + 'static, Layers, C, State, Pipeline> BrokerScope<B, Layers, C, State, Pipeline> {
pub fn include_publishing_on<Source, Def, ReplySource>(
&mut self,
source: Source,
def: Def,
publisher: ReplySource,
) where
Source: SubscriptionSource<Connected<B>> + Send + 'static,
Source::Subscriber: Sync + Send + 'static,
<Source::Subscriber as Subscriber>::Message: Send + Sync + 'static,
C: ScopeCodec,
Def: PublishingCall<State> + 'static,
Def::Input: DecodeWith<<C as ScopeCodec>::Codec>,
Def::Injections: FromStartup<B, Source::Subscriber, ()> + Send + Sync + 'static,
Def::Reply: Send + Sync + 'static,
Def::Context:
BuildContext<<Source::Subscriber as Subscriber>::Message> + Send + Sync + 'static,
ReplySource: PublishPolicy<Connected<B>> + Send + 'static,
ReplySource::Live: ReplySink<Def::Reply, Def::Context, Pipeline> + 'static,
Pipeline: PublishPipeline + Clone + Send + 'static,
State: Send + Sync + 'static,
Layers: Layer<PublishingHandler<Def, C::Codec, ReplySource::Live, Pipeline>>
+ Clone
+ Send
+ 'static,
Layers::Handler:
Handler<<Source::Subscriber as Subscriber>::Message, Def::Context, State> + 'static,
{
self.mount_publishing_source(source, def, publisher, ());
}
pub fn include_batch_publishing_on<Source, Def, ReplySource, BatchReply>(
&mut self,
source: Source,
def: Def,
publisher: ReplySource,
) where
Source: SubscriptionSource<Connected<B>> + Send + 'static,
Source::Subscriber: BatchSubscriber + Sync + Send + 'static,
<Source::Subscriber as Subscriber>::Message: Send + 'static,
C: ScopeCodec,
Def: BatchPublishingCall<State> + 'static,
Def::Input: DecodeWith<<C as ScopeCodec>::Codec>,
Def::Injections: FromStartup<B, Source::Subscriber, ()> + Send + Sync + 'static,
Def::Reply: Serialize + Send + Sync + 'static,
ReplySource: PublishPolicy<Connected<B>, Live = BatchReply> + Send + 'static,
BatchReply: ReplyPublisher + 'static,
Pipeline: PublishPipeline + Clone + Send + 'static,
State: Send + Sync + 'static,
{
self.mount_batch_publishing_source(source, def, publisher, ());
}
}