summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorihc童鞋@提不起劲 <[email protected]>2023-04-18 19:16:03 +0800
committerGitHub <[email protected]>2023-04-18 19:16:03 +0800
commitef21bca117e057676b435702b463b7a50ed6fb67 (patch)
tree776cefb7d62f0f4fc3663f54c594f4f8e10a0f3c
parent8f65193146370b7e0396dbf175da0521f439599a (diff)
fix: apply lifetime for Sink ans SinkExt trait (#160)
-rw-r--r--monoio/Cargo.toml2
-rw-r--r--monoio/src/io/sink/mod.rs14
-rw-r--r--monoio/src/io/sink/sink_ext.rs15
3 files changed, 21 insertions, 10 deletions
diff --git a/monoio/Cargo.toml b/monoio/Cargo.toml
index 2328365..42c4fc7 100644
--- a/monoio/Cargo.toml
+++ b/monoio/Cargo.toml
@@ -8,7 +8,7 @@ license = "MIT/Apache-2.0"
name = "monoio"
readme = "README.md"
repository = "https://github.com/bytedance/monoio"
-version = "0.1.1"
+version = "0.1.2"
# common dependencies
[dependencies]
diff --git a/monoio/src/io/sink/mod.rs b/monoio/src/io/sink/mod.rs
index d1c55ac..f9bfc7a 100644
--- a/monoio/src/io/sink/mod.rs
+++ b/monoio/src/io/sink/mod.rs
@@ -12,7 +12,8 @@ pub trait Sink<Item> {
/// Future representing the send result.
type SendFuture<'a>: std::future::Future<Output = Result<(), Self::Error>>
where
- Self: 'a;
+ Self: 'a,
+ Item: 'a;
/// Future representing the flush result.
type FlushFuture<'a>: std::future::Future<Output = Result<(), Self::Error>>
@@ -25,7 +26,9 @@ pub trait Sink<Item> {
Self: 'a;
/// Send item.
- fn send(&mut self, item: Item) -> Self::SendFuture<'_>;
+ fn send<'a>(&'a mut self, item: Item) -> Self::SendFuture<'a>
+ where
+ Item: 'a;
/// Flush any remaining output from this sink.
fn flush(&mut self) -> Self::FlushFuture<'_>;
@@ -39,7 +42,7 @@ impl<T, S: ?Sized + Sink<T>> Sink<T> for &mut S {
type SendFuture<'a> = S::SendFuture<'a>
where
- Self: 'a;
+ Self: 'a, T: 'a;
type FlushFuture<'a> = S::FlushFuture<'a>
where
@@ -49,7 +52,10 @@ impl<T, S: ?Sized + Sink<T>> Sink<T> for &mut S {
where
Self: 'a;
- fn send(&mut self, item: T) -> Self::SendFuture<'_> {
+ fn send<'a>(&'a mut self, item: T) -> Self::SendFuture<'a>
+ where
+ T: 'a,
+ {
(**self).send(item)
}
diff --git a/monoio/src/io/sink/sink_ext.rs b/monoio/src/io/sink/sink_ext.rs
index e02f605..2b10bd8 100644
--- a/monoio/src/io/sink/sink_ext.rs
+++ b/monoio/src/io/sink/sink_ext.rs
@@ -5,21 +5,26 @@ pub trait SinkExt<T>: Sink<T> {
/// SendFlushFuture.
type SendFlushFuture<'a>: std::future::Future<Output = Result<(), Self::Error>> + 'a
where
- Self: 'a;
+ Self: 'a,
+ T: 'a;
/// Send and flush.
- fn send_and_flush(&mut self, item: T) -> Self::SendFlushFuture<'_>;
+ fn send_and_flush<'a>(&'a mut self, item: T) -> Self::SendFlushFuture<'a>
+ where
+ T: 'a;
}
impl<T, A> SinkExt<T> for A
where
A: Sink<T>,
- T: 'static,
{
type SendFlushFuture<'a> = impl std::future::Future<Output = Result<(), Self::Error>> + 'a where
- A: 'a;
+ A: 'a, T: 'a;
- fn send_and_flush(&mut self, item: T) -> Self::SendFlushFuture<'_> {
+ fn send_and_flush<'a>(&'a mut self, item: T) -> Self::SendFlushFuture<'a>
+ where
+ T: 'a,
+ {
async move {
Sink::<T>::send(self, item).await?;
Sink::<T>::flush(self).await