Skip to content

Commit

Permalink
chore: fix clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
aqrln committed Oct 16, 2024
1 parent 4c05a47 commit e867b1c
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 16 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ documentation = "https://docs.rs/mobc/latest/mobc/"
[features]
default = ["tokio", "unstable"]
unstable = []
docs = []

[dependencies]
futures-core = "0.3"
Expand Down Expand Up @@ -48,5 +49,5 @@ name = "tide"
required-features = ["async-std"]

[package.metadata.docs.rs]
features = ["unstable"]
features = ["unstable", "docs"]
rustdoc-args = ["--cfg", "feature=\"unstable\""]
4 changes: 1 addition & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -454,9 +454,7 @@ impl<M: Manager> Pool<M> {
}
}

let create_r = self.open_new_connection(permit).await;

create_r
self.open_new_connection(permit).await
}

async fn open_new_connection(
Expand Down
30 changes: 20 additions & 10 deletions src/runtime.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! A batteries included runtime for applications using mobc.
//! Mobc does not implement runtime, it simply exports runtime.

pub use runtime::{DefaultExecutor, Runtime, TaskExecutor};
pub use internal::{DefaultExecutor, Runtime, TaskExecutor};

use std::future::Future;
use std::pin::Pin;
Expand All @@ -21,30 +21,30 @@ pub trait Executor: Send + Sync + 'static + Clone {
}

#[cfg(all(feature = "tokio", not(feature = "async-std")))]
mod runtime {
mod internal {
use super::*;

/// Wrapper of the Tokio Runtime
/// Wrapper of the Tokio Runtime.
pub struct Runtime {
rt: tokio::runtime::Runtime,
spawner: TaskExecutor,
}

impl Runtime {
/// Creates a new Runtime
/// Creates a new [`Runtime`].
pub fn new() -> Option<Self> {
Some(Runtime {
rt: tokio::runtime::Runtime::new().unwrap(),
spawner: TaskExecutor,
})
}

/// Returns a spawner
/// Returns a spawner.
pub fn handle(&self) -> &TaskExecutor {
&self.spawner
}

/// Run a future to completion on the Tokio runtime. This is the
/// Runs a future to completion on the Tokio runtime. This is the
/// runtime's entry point.
pub fn block_on<F, T>(&mut self, future: F) -> T
where
Expand All @@ -53,7 +53,7 @@ mod runtime {
self.rt.block_on(future)
}

/// Spawn a future onto the Tokio runtime.
/// Spawns a future onto the Tokio runtime.
pub fn spawn<F, T>(&self, future: F)
where
F: Future<Output = T> + Send + 'static,
Expand All @@ -68,7 +68,7 @@ mod runtime {
pub struct TaskExecutor;

impl TaskExecutor {
/// Spawn a future onto the Tokio runtime.
/// Spawns a future onto the Tokio runtime.
pub fn spawn<F>(&self, future: F)
where
F: Future + Send + 'static,
Expand Down Expand Up @@ -96,15 +96,17 @@ mod runtime {
}
}

#[cfg(all(feature = "async-std"))]
mod runtime {
#[cfg(feature = "async-std")]
mod internal {
use super::*;
use async_std::task;

/// Simple handler for spawning task
#[derive(Clone)]
pub struct TaskExecutor;

impl TaskExecutor {
/// Spawns a future onto async-std runtime.
pub fn spawn<F>(&self, future: F)
where
F: Future + Send + 'static,
Expand All @@ -114,24 +116,30 @@ mod runtime {
}
}

/// Wrapper of the async-std runtime.
pub struct Runtime(TaskExecutor);

impl Runtime {
/// Creates a new [`Runtime`].
pub fn new() -> Option<Self> {
Some(Runtime(TaskExecutor))
}

/// Returns a spawner.
pub fn handle(&self) -> &TaskExecutor {
&self.0
}

/// Runs a future to completion on the async-std runtime. This is the
/// runtime's entry point.
pub fn block_on<F, T>(&mut self, future: F) -> T
where
F: Future<Output = T>,
{
task::block_on(future)
}

/// Spawns a future onto the async-std runtime.
pub fn spawn<F, T>(&self, future: F)
where
F: Future<Output = T> + Send + 'static,
Expand All @@ -141,10 +149,12 @@ mod runtime {
}
}

/// The default executor of async-std.
#[derive(Clone)]
pub struct DefaultExecutor;

impl DefaultExecutor {
/// The default executor of async-std.
pub fn current() -> Self {
Self {}
}
Expand Down
5 changes: 3 additions & 2 deletions src/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ use crate::Error;
use futures_util::{select, FutureExt};
use std::future::Future;
use std::time::Duration;
pub use time::{delay_for, interval};

pub use internal::{delay_for, interval};

pub(crate) async fn timeout<F, T, E>(duration: Duration, f: F) -> Result<T, Error<E>>
where
Expand All @@ -14,7 +15,7 @@ where
}
}

mod time {
mod internal {
use std::time::Duration;
use std::time::Instant;

Expand Down

0 comments on commit e867b1c

Please sign in to comment.