You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is more of a question rather than an issue, we're using parking_lot with genawaiter to get an iterator without lifetime from a struct.
use genawaiter::sync::{gen,GenBoxed};use genawaiter::yield_;structExample<T>(Arc<parking_lot::RwLock<Vec<T>>>);impl<T:Clone>Example<T>{fniter(&self) -> implIterator<Item = T>{let tgshard = self.0.clone();let iter:GenBoxed<T> = GenBoxed::new_boxed(|co| asyncmove{let g = tgshard.read();let iter = (*g).iter();for t in iter {
co.yield_(t.clone()).await;}});
iter.into_iter()}}
this is not allowed by the rust compiler because the guard is not Send.
However, is forcing the guard in this scenario (using genawaiter ) to be Send an actual problem?
I don't think the guard will be moved onto another thread. (that being said I have no clue how genawaiter works)
Basically is this workable?
use genawaiter::sync::{gen,GenBoxed};use genawaiter::yield_;structMyLock<T>(parking_lot::RwLock<T>);structMyGuard<'a,T>(parking_lot::RwLockReadGuard<'a,T>);impl<T:Clone>MyLock<T>{fnread(&self) -> MyGuard<T>{MyGuard(self.0.read())}}impl<T>DerefforMyGuard<'_,T>{typeTarget = T;fnderef(&self) -> &Self::Target{self.0.deref()}}unsafeimpl<T>SendforMyGuard<'_,T>{}structExample2<T>(Arc<MyLock<Vec<T>>>);impl<T:Clone + std::marker::Send + std::marker::Sync + 'static>Example2<T>{fniter(&self) -> implIterator<Item = T>{let tgshard = self.0.clone();let iter:GenBoxed<T> = GenBoxed::new_boxed(|co| asyncmove{let g = tgshard.read();let iter = (*g).iter();for t in iter {
co.yield_(t.clone()).await;}});
iter.into_iter()}}
The text was updated successfully, but these errors were encountered:
This is more of a question rather than an issue, we're using
parking_lot
with genawaiter to get an iterator without lifetime from a struct.this is not allowed by the rust compiler because the guard is not Send.
However, is forcing the guard in this scenario (using
genawaiter
) to be Send an actual problem?I don't think the guard will be moved onto another thread. (that being said I have no clue how genawaiter works)
Basically is this workable?
The text was updated successfully, but these errors were encountered: