1use std::future::Future;
2use std::pin::Pin;
3use std::task::{Context, Poll};
4
5pub struct FrameFuture {
7 inner: Pin<Box<dyn Future<Output = crate::Result<crate::Frame>> + Send>>,
8}
9
10impl FrameFuture {
11 pub fn new(inner: Pin<Box<dyn Future<Output = crate::Result<crate::Frame>> + Send>>) -> Self {
13 Self { inner }
14 }
15
16 pub fn from_async_block<F>(future: F) -> Self
18 where
19 F: Future<Output = crate::Result<crate::Frame>> + Send + 'static,
20 {
21 Self::new(Box::pin(future))
22 }
23
24 pub fn from_frame(frame: crate::Frame) -> Self {
26 Self::from_result(Ok(frame))
27 }
28
29 pub fn from_result(result: crate::Result<crate::Frame>) -> Self {
31 Self::from_async_block(async move { result })
32 }
33
34 pub fn from_frame_futures(futures: Vec<FrameFuture>) -> Self {
36 Self::from_async_block(async move {
37 let mut frames = Vec::new();
38
39 for future in futures {
40 frames.push(future.await?);
41 }
42
43 Ok(frames.into())
44 })
45 }
46
47 pub fn empty() -> Self {
49 Self::from_frame(crate::Frame::default())
50 }
51}
52
53impl Future for FrameFuture {
54 type Output = crate::Result<crate::Frame>;
55
56 fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
57 self.get_mut().inner.as_mut().poll(cx)
58 }
59}