Skip to content
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
1 change: 0 additions & 1 deletion cot/src/middleware/live_reload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ mod tests {
test_live_reload_from_context(false).await;
}

#[expect(clippy::future_not_send, reason = "test function using Bootstrapper")]
async fn test_live_reload_from_context(enabled: bool) {
struct TestProject;
impl Project for TestProject {}
Expand Down
32 changes: 7 additions & 25 deletions cot/src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -849,7 +849,7 @@ async fn default_error_handler(error: RequestOuterError) -> crate::Result<impl I
#[derive(Debug)]
pub struct Bootstrapper<S: BootstrapPhase = Initialized> {
#[debug("..")]
project: Box<dyn Project>,
project: Box<dyn Project + Send>,
context: ProjectContext<S>,
handler: S::RequestHandler,
error_handler: S::ErrorHandler,
Expand All @@ -874,7 +874,7 @@ impl Bootstrapper<Uninitialized> {
/// # }
/// ```
#[must_use]
pub fn new<P: Project + 'static>(project: P) -> Self {
pub fn new<P: Project + Send + 'static>(project: P) -> Self {
Self {
project: Box::new(project),
context: ProjectContext::new(),
Expand Down Expand Up @@ -1085,8 +1085,6 @@ impl Bootstrapper<WithConfig> {
/// # Ok(())
/// # }
/// ```
// Send not needed; Bootstrapper is run async in a single thread
#[expect(clippy::future_not_send)]
pub async fn boot(self) -> cot::Result<Bootstrapper<Initialized>> {
self.with_apps().boot().await
}
Expand Down Expand Up @@ -1171,8 +1169,6 @@ impl Bootstrapper<WithApps> {
/// # Ok(())
/// # }
/// ```
// Send not needed; Bootstrapper is run async in a single thread
#[expect(clippy::future_not_send)]
pub async fn boot(self) -> cot::Result<Bootstrapper<Initialized>> {
self.with_database().await?.boot().await
}
Expand Down Expand Up @@ -1209,8 +1205,6 @@ impl Bootstrapper<WithApps> {
/// # Ok(())
/// # }
/// ```
// Send not needed; Bootstrapper is run async in a single thread
#[expect(clippy::future_not_send)]
pub async fn with_database(self) -> cot::Result<Bootstrapper<WithDatabase>> {
#[cfg(feature = "db")]
let database = Self::init_database(&self.context.config.database).await?;
Expand Down Expand Up @@ -1275,8 +1269,6 @@ impl Bootstrapper<WithDatabase> {
/// # }
/// ```
// Function marked `async` to be consistent with the other `boot` methods
// Send not needed; Bootstrapper is run async in a single thread
#[expect(clippy::future_not_send)]
pub async fn boot(self) -> cot::Result<Bootstrapper<Initialized>> {
self.with_cache().await?.boot().await
}
Expand Down Expand Up @@ -1314,7 +1306,6 @@ impl Bootstrapper<WithDatabase> {
/// # Ok(())
/// # }
/// ```
#[expect(clippy::future_not_send)]
#[allow(
clippy::unused_async,
clippy::allow_attributes,
Expand Down Expand Up @@ -1379,7 +1370,10 @@ impl Bootstrapper<WithCache> {
/// # Ok(())
/// # }
/// ```
#[expect(clippy::unused_async, clippy::future_not_send)]
#[expect(
clippy::unused_async,
reason = "for consistency with other Bootstrapper::boot methods"
)]
pub async fn boot(self) -> cot::Result<Bootstrapper<Initialized>> {
let router_service = RouterService::new(Arc::clone(&self.context.router));
let handler_builder = RootHandlerBuilder {
Expand Down Expand Up @@ -2057,10 +2051,6 @@ impl<S: BootstrapPhase<Database = Option<Database>>> ProjectContext<S> {
/// # Errors
///
/// This function returns an error if the server fails to start.
#[expect(
clippy::future_not_send,
reason = "Send not needed; Bootstrapper/CLI is run async in a single thread"
)]
pub async fn run(bootstrapper: Bootstrapper<Initialized>, address_str: &str) -> cot::Result<()> {
let listener = tokio::net::TcpListener::bind(address_str)
.await
Expand All @@ -2082,10 +2072,6 @@ pub async fn run(bootstrapper: Bootstrapper<Initialized>, address_str: &str) ->
/// # Errors
///
/// This function returns an error if the server fails to start.
#[expect(
clippy::future_not_send,
reason = "Send not needed; Bootstrapper/CLI is run async in a single thread"
)]
pub async fn run_at(
bootstrapper: Bootstrapper<Initialized>,
listener: tokio::net::TcpListener,
Expand All @@ -2106,10 +2092,6 @@ pub async fn run_at(
/// # Errors
///
/// This function returns an error if the server fails to start.
#[expect(
clippy::future_not_send,
reason = "Send not needed; Bootstrapper/CLI is run async in a single thread"
)]
pub async fn run_at_with_shutdown(
bootstrapper: Bootstrapper<Initialized>,
listener: tokio::net::TcpListener,
Expand Down Expand Up @@ -2326,7 +2308,7 @@ pub(crate) fn prepare_request_for_error_handler(request_head: &mut RequestHead,
/// # }
/// ```
#[expect(clippy::future_not_send)] // Send not needed; CLI is run async in a single thread
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we now require Send here, do we still need this clippy attribute here (as well as the comment) or am I missing something?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question! This particular function is not Send because it uses CliTask, which is explicitly marked as not requiring Send:

#[async_trait(?Send)]

I think it might still potentially be useful to create CLI tasks that contain some non-Send data, and by definition, they shouldn't be ran as part of other applications, especially in already existing async runtimes. I'm, however, happy to be wrong - if you think like there's a use case for this, then I'm happy to drop this Send requirement as well.

pub async fn run_cli(project: impl Project + 'static) -> cot::Result<()> {
pub async fn run_cli(project: impl Project + Send + 'static) -> cot::Result<()> {
Bootstrapper::new(project).run_cli().await
}

Expand Down
7 changes: 3 additions & 4 deletions cot/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,9 @@ impl Client {
/// }
/// ```
#[must_use]
#[expect(clippy::future_not_send)] // used in the test code
pub async fn new<P>(project: P) -> Self
where
P: Project + 'static,
P: Project + Send + 'static,
{
let config = project.config("test").expect("Could not get test config");
let bootstrapper = Bootstrapper::new(project)
Expand Down Expand Up @@ -1351,7 +1350,7 @@ pub struct TestServerBuilder<T> {
project: T,
}

impl<T: Project + 'static> TestServerBuilder<T> {
impl<T: Project + Send + 'static> TestServerBuilder<T> {
/// Create a new test server.
///
/// # Examples
Expand Down Expand Up @@ -1444,7 +1443,7 @@ pub struct TestServer<T> {
project: PhantomData<fn() -> T>,
}

impl<T: Project + 'static> TestServer<T> {
impl<T: Project + Send + 'static> TestServer<T> {
async fn start(project: T) -> Self {
let tcp_listener = TcpListener::bind("0.0.0.0:0")
.await
Expand Down
Loading