From 0bee87b693aacfedc371b27c7a5c97db759c2fa6 Mon Sep 17 00:00:00 2001
From: Jason Volk <jason@zemos.net>
Date: Sun, 6 Apr 2025 05:42:27 +0000
Subject: [PATCH] add ready_find() stream extension

Signed-off-by: Jason Volk <jason@zemos.net>
---
 src/core/utils/stream/ready.rs | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/src/core/utils/stream/ready.rs b/src/core/utils/stream/ready.rs
index 38feaf64..be4d1b25 100644
--- a/src/core/utils/stream/ready.rs
+++ b/src/core/utils/stream/ready.rs
@@ -2,7 +2,7 @@
 #![allow(clippy::type_complexity)]
 
 use futures::{
-	future::{Ready, ready},
+	future::{FutureExt, Ready, ready},
 	stream::{
 		All, Any, Filter, FilterMap, Fold, ForEach, Scan, SkipWhile, Stream, StreamExt, TakeWhile,
 	},
@@ -26,6 +26,12 @@ where
 	where
 		F: Fn(Item) -> bool;
 
+	fn ready_find<'a, F>(self, f: F) -> impl Future<Output = Option<Item>> + Send
+	where
+		Self: Send + Unpin + 'a,
+		F: Fn(&Item) -> bool + Send + 'a,
+		Item: Send;
+
 	fn ready_filter<'a, F>(
 		self,
 		f: F,
@@ -111,6 +117,19 @@ where
 		self.any(move |t| ready(f(t)))
 	}
 
+	#[inline]
+	fn ready_find<'a, F>(self, f: F) -> impl Future<Output = Option<Item>> + Send
+	where
+		Self: Send + Unpin + 'a,
+		F: Fn(&Item) -> bool + Send + 'a,
+		Item: Send,
+	{
+		self.ready_filter(f)
+			.take(1)
+			.into_future()
+			.map(|(curr, _next)| curr)
+	}
+
 	#[inline]
 	fn ready_filter<'a, F>(
 		self,