remove async-trait
This commit is contained in:
parent
2f708060f7
commit
16d7c47e42
|
@ -1 +1,2 @@
|
|||
**target/
|
||||
**Cargo.lock
|
|
@ -13,7 +13,6 @@ bincode = "1"
|
|||
overwatch-rs = { path = "../../overwatch-rs" }
|
||||
overwatch-derive = { path = "../../overwatch-derive" }
|
||||
tracing = "*"
|
||||
async-trait = "0.1"
|
||||
tracing-subscriber = "0.3"
|
||||
clap = { version = "4.0.18", features = ["derive"] }
|
||||
rand = "0.8"
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
use crate::network::*;
|
||||
use async_trait::async_trait;
|
||||
use overwatch_rs::services::handle::ServiceStateHandle;
|
||||
use overwatch_rs::services::relay::{NoMessage, OutboundRelay};
|
||||
use overwatch_rs::services::state::{NoOperator, NoState};
|
||||
|
@ -27,7 +26,6 @@ impl ServiceData for ChatService {
|
|||
type Message = NoMessage;
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl ServiceCore for ChatService {
|
||||
fn init(service_state: ServiceStateHandle<Self>) -> Result<Self, overwatch_rs::DynError> {
|
||||
Ok(Self { service_state })
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
pub mod waku;
|
||||
use async_trait::async_trait;
|
||||
use overwatch_rs::services::handle::ServiceStateHandle;
|
||||
use overwatch_rs::services::relay::RelayMessage;
|
||||
use overwatch_rs::services::state::{NoOperator, NoState};
|
||||
|
@ -47,7 +46,6 @@ impl<I: NetworkBackend + Send + 'static> ServiceData for NetworkService<I> {
|
|||
type Message = NetworkMsg;
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl<I: NetworkBackend + Send + 'static> ServiceCore for NetworkService<I> {
|
||||
fn init(mut service_state: ServiceStateHandle<Self>) -> Result<Self, overwatch_rs::DynError> {
|
||||
Ok(Self {
|
||||
|
|
|
@ -26,7 +26,6 @@ derive = ["dep:overwatch-derive"]
|
|||
overwatch-derive = { path = "../overwatch-derive", optional = true }
|
||||
const-str = "0.3"
|
||||
color-eyre = "0.6"
|
||||
async-trait = "0.1"
|
||||
futures = "0.3"
|
||||
thiserror = "1.0"
|
||||
tokio = { version = "1.32", features = ["rt-multi-thread", "sync", "time"] }
|
||||
|
|
|
@ -9,7 +9,6 @@ use std::future::Future;
|
|||
|
||||
// crates
|
||||
|
||||
use async_trait::async_trait;
|
||||
use thiserror::Error;
|
||||
use tokio::runtime::{Handle, Runtime};
|
||||
use tokio::sync::mpsc::Receiver;
|
||||
|
@ -62,7 +61,6 @@ pub type AnySettings = Box<dyn Any + Send>;
|
|||
|
||||
/// An overwatch run anything that implements this trait
|
||||
/// An implementor of this trait would have to handle the inner [`ServiceCore`](crate::services::ServiceCore)
|
||||
#[async_trait]
|
||||
pub trait Services: Sized {
|
||||
/// Inner [`ServiceCore::Settings`](crate::services::ServiceCore) grouping type.
|
||||
/// Normally this will be a settings object that group all the inner services settings.
|
||||
|
|
|
@ -7,7 +7,7 @@ pub mod state;
|
|||
// std
|
||||
use std::fmt::Debug;
|
||||
// crates
|
||||
use async_trait::async_trait;
|
||||
use futures::Future;
|
||||
use thiserror::Error;
|
||||
use tokio::runtime;
|
||||
|
||||
|
@ -40,13 +40,12 @@ pub trait ServiceData {
|
|||
}
|
||||
|
||||
/// Main trait for Services initialization and main loop hook
|
||||
#[async_trait]
|
||||
pub trait ServiceCore: Sized + ServiceData {
|
||||
/// Initialize the service with the given state
|
||||
fn init(service_state: ServiceStateHandle<Self>) -> Result<Self, super::DynError>;
|
||||
|
||||
/// Service main loop
|
||||
async fn run(mut self) -> Result<(), super::DynError>;
|
||||
fn run(self) -> impl Future<Output = Result<(), super::DynError>> + Send;
|
||||
}
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
// std
|
||||
use std::marker::PhantomData;
|
||||
use std::pin::Pin;
|
||||
use std::sync::Arc;
|
||||
// crates
|
||||
use async_trait::async_trait;
|
||||
use futures::StreamExt;
|
||||
use futures::{Future, StreamExt};
|
||||
use tokio::sync::watch::{channel, Receiver, Ref, Sender};
|
||||
use tokio_stream::wrappers::WatchStream;
|
||||
use tracing::error;
|
||||
|
@ -26,14 +24,13 @@ pub trait ServiceState: Sized {
|
|||
|
||||
/// A state operator is an entity that can handle a state in a point of time
|
||||
/// to perform any operation based on it.
|
||||
#[async_trait]
|
||||
pub trait StateOperator {
|
||||
/// The type of state that the operator can handle
|
||||
type StateInput: ServiceState;
|
||||
/// Operator initialization method. Can be implemented over some subset of settings
|
||||
fn from_settings<Settings>(settings: Settings) -> Self;
|
||||
/// Asynchronously perform an operation for a given state
|
||||
async fn run(&mut self, state: Self::StateInput);
|
||||
fn run(&mut self, state: Self::StateInput) -> impl Future<Output = ()> + Send;
|
||||
}
|
||||
|
||||
/// Operator that doesn't perform any operation upon state update
|
||||
|
@ -53,24 +50,14 @@ impl<T> Clone for NoOperator<T> {
|
|||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl<StateInput: ServiceState> StateOperator for NoOperator<StateInput> {
|
||||
impl<StateInput: ServiceState + Send> StateOperator for NoOperator<StateInput> {
|
||||
type StateInput = StateInput;
|
||||
|
||||
fn from_settings<Settings>(_settings: Settings) -> Self {
|
||||
NoOperator(PhantomData)
|
||||
}
|
||||
|
||||
fn run<'borrow, 'fut>(
|
||||
&'borrow mut self,
|
||||
_state: Self::StateInput,
|
||||
) -> Pin<Box<dyn std::future::Future<Output = ()> + Send + 'fut>>
|
||||
where
|
||||
'borrow: 'fut,
|
||||
Self: 'fut,
|
||||
{
|
||||
Box::pin(async {})
|
||||
}
|
||||
async fn run(&mut self, _state: Self::StateInput) {}
|
||||
}
|
||||
|
||||
/// Empty state
|
||||
|
@ -207,7 +194,6 @@ where
|
|||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::services::state::{ServiceState, StateHandle, StateOperator, StateUpdater};
|
||||
use async_trait::async_trait;
|
||||
use std::time::Duration;
|
||||
use tokio::io;
|
||||
use tokio::io::AsyncWriteExt;
|
||||
|
@ -226,7 +212,6 @@ mod test {
|
|||
|
||||
struct PanicOnGreaterThanTen;
|
||||
|
||||
#[async_trait]
|
||||
impl StateOperator for PanicOnGreaterThanTen {
|
||||
type StateInput = UsizeCounter;
|
||||
|
||||
|
|
|
@ -23,7 +23,6 @@ impl ServiceData for CancellableService {
|
|||
type Message = NoMessage;
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl ServiceCore for CancellableService {
|
||||
fn init(service_state: ServiceStateHandle<Self>) -> Result<Self, DynError> {
|
||||
Ok(Self { service_state })
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
use async_trait::async_trait;
|
||||
use futures::future::select;
|
||||
use overwatch_derive::Services;
|
||||
use overwatch_rs::overwatch::OverwatchRunner;
|
||||
|
@ -34,7 +33,6 @@ where
|
|||
type Message = GenericServiceMessage;
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl<T: Send> ServiceCore for GenericService<T>
|
||||
where
|
||||
T: Debug + 'static + Sync,
|
||||
|
@ -46,7 +44,7 @@ where
|
|||
})
|
||||
}
|
||||
|
||||
async fn run(mut self) -> Result<(), overwatch_rs::DynError> {
|
||||
async fn run(self) -> Result<(), overwatch_rs::DynError> {
|
||||
use tokio::io::{self, AsyncWriteExt};
|
||||
|
||||
let Self {
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
use async_trait::async_trait;
|
||||
use futures::future::select;
|
||||
use overwatch_derive::Services;
|
||||
use overwatch_rs::overwatch::OverwatchRunner;
|
||||
|
@ -26,13 +25,12 @@ impl ServiceData for PrintService {
|
|||
type Message = PrintServiceMessage;
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl ServiceCore for PrintService {
|
||||
fn init(state: ServiceStateHandle<Self>) -> Result<Self, overwatch_rs::DynError> {
|
||||
Ok(Self { state })
|
||||
}
|
||||
|
||||
async fn run(mut self) -> Result<(), overwatch_rs::DynError> {
|
||||
async fn run(self) -> Result<(), overwatch_rs::DynError> {
|
||||
use tokio::io::{self, AsyncWriteExt};
|
||||
|
||||
let Self {
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
use async_trait::async_trait;
|
||||
use overwatch_derive::Services;
|
||||
use overwatch_rs::overwatch::OverwatchRunner;
|
||||
use overwatch_rs::services::handle::{ServiceHandle, ServiceStateHandle};
|
||||
|
@ -27,13 +26,12 @@ impl ServiceData for SettingsService {
|
|||
type Message = SettingsMsg;
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl ServiceCore for SettingsService {
|
||||
fn init(state: ServiceStateHandle<Self>) -> Result<Self, overwatch_rs::DynError> {
|
||||
Ok(Self { state })
|
||||
}
|
||||
|
||||
async fn run(mut self) -> Result<(), overwatch_rs::DynError> {
|
||||
async fn run(self) -> Result<(), overwatch_rs::DynError> {
|
||||
let Self {
|
||||
state: ServiceStateHandle {
|
||||
settings_reader, ..
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
use async_trait::async_trait;
|
||||
use overwatch_derive::Services;
|
||||
use overwatch_rs::overwatch::OverwatchRunner;
|
||||
use overwatch_rs::services::handle::{ServiceHandle, ServiceStateHandle};
|
||||
|
@ -46,7 +45,6 @@ impl ServiceState for CounterState {
|
|||
#[derive(Clone)]
|
||||
pub struct CounterStateOperator;
|
||||
|
||||
#[async_trait]
|
||||
impl StateOperator for CounterStateOperator {
|
||||
type StateInput = CounterState;
|
||||
|
||||
|
@ -73,13 +71,12 @@ impl ServiceData for UpdateStateService {
|
|||
type Message = UpdateStateServiceMessage;
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl ServiceCore for UpdateStateService {
|
||||
fn init(state: ServiceStateHandle<Self>) -> Result<Self, overwatch_rs::DynError> {
|
||||
Ok(Self { state })
|
||||
}
|
||||
|
||||
async fn run(mut self) -> Result<(), overwatch_rs::DynError> {
|
||||
async fn run(self) -> Result<(), overwatch_rs::DynError> {
|
||||
let Self {
|
||||
state: ServiceStateHandle { state_updater, .. },
|
||||
} = self;
|
||||
|
|
Loading…
Reference in New Issue