Hi,
Trying to forward a stream of (midi and clock) events to a simple Iced UI and I'm having a few problems.
So far things seem very upset due to Iced wanting 'static lifetime, but also I'm relatively new at rust so maybe making some fundament errors with pinning and lifetimes and such. I'm looking at the iced/download.rs example and the Recipe constructor for making a bridge from the Reciever (channel) but I guess I'm just missing something obvious/fundamental (I hope).
The relevant bits of my code are (this is all brutally copied from the example, names are as such):
struct Example<'a> {
processed_rx_stream: BoxStream<'a, Progress>,
_pin: PhantomPinned,
}
pub struct Download<'a, I> {
id: I,
processed_rx_stream: BoxStream<'a, Progress>,
_pin: PhantomPinned,
}
impl<H, I, T> iced_native::subscription::Recipe<H, I> for Download<'_, T>
where
T: 'static + Hash + Copy + Send,
H: Hasher,
{
type Output = (T, Progress);
fn stream(
self: Box<Self>,
_input: futures::stream::BoxStream<'static, I>,
) -> futures::stream::BoxStream<'static, Self::Output> {
self.processed_rx_stream
}
}
impl Application for Example<'static> {
fn new(_flags: ()) -> (Example<'static>, Command<Self::Message>) {
use std::thread;
let (processed_send, processed_rx) = flume::unbounded::<Progress>();
thread::spawn(move || loop {
thread::sleep(Duration::from_millis(200));
processed_send.send(Progress::Tick);
});
let st = processed_rx.into_stream();
let processed_rx_stream = Box::pin(st);
let (panes, _) = pane_grid::State::new(Content::new(0));
(Example {
processed_rx_stream,
_pin: PhantomPinned,
}, Command::none())
}
}
I have errors like:
= note: expected `Pin<Box<(dyn iced::futures::Stream<Item = Progress> + std::marker::Send + 'static)>>`
found `Pin<Box<dyn iced::futures::Stream<Item = Progress> + std::marker::Send>>`
I guess the basic question is how can I make my stream 'static so it fits with the return type below?
fn stream(
self: Box<Self>,
_input: futures::stream::BoxStream<'static, I>,
) -> futures::stream::BoxStream<'static, Self::Output> {