Skip to content

Remove dependency on async-trait. #1922

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ arbitrary = { version = "1.0" }
libc = "0.2.150"
tokio = "1.32"
toml = { version = ">=0.6.0,<0.9.0", default-features = false, features = ["parse"] }
async-trait = "0.1.67"
timestamped-socket = "0.2.2"
clock-steering = "0.2.1"
pps-time = "0.2.3"
Expand Down
1 change: 0 additions & 1 deletion ntpd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ tracing-subscriber.workspace = true
toml.workspace = true
rand.workspace = true
libc.workspace = true
async-trait.workspace = true
timestamped-socket.workspace = true
clock-steering.workspace = true
pps-time = { workspace = true, optional = true }
Expand Down
20 changes: 12 additions & 8 deletions ntpd/src/daemon/spawn/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{net::SocketAddr, path::PathBuf, sync::atomic::AtomicU64};
use std::{future::Future, net::SocketAddr, path::PathBuf, sync::atomic::AtomicU64};

use ntp_proto::{ProtocolVersion, SourceConfig, SourceNtsData};
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -190,7 +190,6 @@ pub struct PpsSourceCreateParameters {
pub period: f64,
}

#[async_trait::async_trait]
pub trait Spawner {
type Error: std::error::Error + Send;

Expand All @@ -199,7 +198,10 @@ pub trait Spawner {
/// It is ok for this function to use some time when spawning a new client.
/// However, it should not implement it's own retry or backoff feature, but
/// rather rely on that provided by the basic spawner.
async fn try_spawn(&mut self, action_tx: &mpsc::Sender<SpawnEvent>) -> Result<(), Self::Error>;
fn try_spawn(
&mut self,
action_tx: &mpsc::Sender<SpawnEvent>,
) -> impl Future<Output = Result<(), Self::Error>> + Send;

/// Is there desire to spawn new sources?
fn is_complete(&self) -> bool;
Expand All @@ -213,8 +215,10 @@ pub trait Spawner {
///
/// This should just do bookkeeping, any adding of sources should be done
/// in try_add.
async fn handle_source_removed(&mut self, event: SourceRemovedEvent)
-> Result<(), Self::Error>;
fn handle_source_removed(
&mut self,
event: SourceRemovedEvent,
) -> impl Future<Output = Result<(), Self::Error>> + Send;

/// Event handler for when a source is successfully registered in the system
///
Expand All @@ -224,11 +228,11 @@ pub trait Spawner {
///
/// This should just do bookkeeping, any adding of sources should be done
/// in try_add.
async fn handle_registered(
fn handle_registered(
&mut self,
_event: SourceCreateParameters,
) -> Result<(), Self::Error> {
Ok(())
) -> impl Future<Output = Result<(), Self::Error>> + Send {
async { Ok(()) }
}

/// Get the id of the spawner
Expand Down
1 change: 0 additions & 1 deletion ntpd/src/daemon/spawn/nts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ impl NtsSpawner {
}
}

#[async_trait::async_trait]
impl Spawner for NtsSpawner {
type Error = NtsSpawnError;

Expand Down
1 change: 0 additions & 1 deletion ntpd/src/daemon/spawn/nts_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ impl NtsPoolSpawner {
}
}

#[async_trait::async_trait]
impl Spawner for NtsPoolSpawner {
type Error = NtsPoolSpawnError;

Expand Down
1 change: 0 additions & 1 deletion ntpd/src/daemon/spawn/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ impl PoolSpawner {
}
}

#[async_trait::async_trait]
impl Spawner for PoolSpawner {
type Error = PoolSpawnError;

Expand Down
1 change: 0 additions & 1 deletion ntpd/src/daemon/spawn/pps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ impl PpsSpawner {
}
}

#[async_trait::async_trait]
impl Spawner for PpsSpawner {
type Error = StandardSpawnError;

Expand Down
1 change: 0 additions & 1 deletion ntpd/src/daemon/spawn/sock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ impl SockSpawner {
}
}

#[async_trait::async_trait]
impl Spawner for SockSpawner {
type Error = StandardSpawnError;

Expand Down
1 change: 0 additions & 1 deletion ntpd/src/daemon/spawn/standard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ impl StandardSpawner {
}
}

#[async_trait::async_trait]
impl Spawner for StandardSpawner {
type Error = StandardSpawnError;

Expand Down
Loading