Expand description
SOD: Service-Oriented Design
This crate provides Service
, MutService
, and AsyncService
traits and associated utilities to facilitiate service-oriented design.
These traits and tools in this library provide concrete guidelines to help make a service-oriented design successful.
In the context of this crate, a service is simply a trait that accepts an input and produces a result.
Traits can be composed or chained together using the ServiceChain
found in this crate.
This crate in and of itself does not provide mechanisms to expose services on a network or facilitiate service discovery.
Those implementation details are to be provided in sod-*
crates, which will often simply encapsulate other open source libraries to expose them as services.
Instead, this crate provides the core mechanisms to define services in a way that helps guarantee they will be interoperable with one another at a library level.
Modules
- Idle functions that may optionally be used by
crate::RetryService
andcrate::PollService
.
Structs
- A
Service
, which encapsulates anArc<Service<Input>>
. - A
Service
, which encapsulates anArc<Service<Input>>
. - Returned by
ServiceChain::start_async
to build an async service chain. Use thenext(self, AsyncService)
function to append more services to theServiceChain
. Use theend(self)
function to finish building and return the resultingServiceChain
. - Clone a
Borrow<T>
input, producing the clonedT
value as output - A
Service
,MutService
, orAsyncService
that encapsulates two service and accepts aClone
able input, which is passed to both underlying services, returning their outputs as a tuple. - An
AsyncService
which encapsulates aBox<dyn AsyncService<...>>
. - A
MutService
which encapsulates aBox<dyn MutService<...>>
. - A
Service
which encapsulates aBox<dyn Service<...>>
. - A
Service
that processes aOption<T>
as input, processing with an underlying [Service<Input = T>
] when the input isSome
, producingOption<S::Output>
as output. - Returned by
ServiceChain::start_mut
to build a mut service chain. Use thenext(self, MutService)
function to append more services to theServiceChain
. Use theend(self)
function to finish building and return the resultingServiceChain
. - A
Service
, which encapsulates aMutService
, usingstd::sync::Mutex
to aquire mutability in each call toprocess
. - A
Service
which no-ops, passing the input asOk(output)
. - A
Service
,MutService
, orAsyncService
, which encapsulates aService<(), Output = Option<T>>
,MutService<(), Output = Option<T>>
, orAsyncService<(), Output = Option<T>>
, blocking with the given idle function until a value is returned or the idle function returns an error. - A
Service
, which encapsulates aMutService
, usingstd::cell::RefCell
to aquire mutability in each call toprocess
. - A
Service
,MutService
, orAsyncService
that encapsulates two service and accepts a input as a reference, which is passed to both underlying services, returning their outputs as a tuple. - A
Service
,MutService
, orAsyncService
, which encapsulates aRetryable
, blocking and retrying until a value is returned, an un-retryable error is encountered, or the idle function returns anErr
. - A chain of
Service
,MutService
, orAsyncService
implementations, which is itself a singleService
,MutService
, orAsyncService
that accepts the first service in the chain’s input and produces the the last service in the chain’s output. When any service in the chain returns anErr
, the chain will break early, encapsulate the error in aServiceChainError
, and returnErr(ServiceChainError)
immediately. - Returned by
ServiceChain::start
to build a sync service chain. Use thenext(self, Service)
function to append more services to theServiceChain
. Use theend(self)
function to finish building and return the resultingServiceChain
. - A
Service
that accepts aFnOnce()
as input, which is passed tospawn()
, and produces aJoinHandle
as output. - A
Service
that will returnOk(Input)
when the provided function returns true, or orErr(Stopped)
when the provided function returns false. - A generic error that indicates stoppage
Enums
- Used by idle and retry services to interrupt a poll or retry loop
Traits
- An async service trait
- A mut service trait
- To be implemented by non-blocking services which may return the moved input in a resulting
Err
to be retried. - A sync service trait
Attribute Macros
- Provide support for
async fn
by exposing the externalasync_trait
crate. Seeasync_trait
for details.