提问人:Vana 提问时间:1/16/2023 最后编辑:Vana 更新时间:1/16/2023 访问量:229
特征“futures::Stream”没有为我的类型实现
the trait `futures::Stream` is not implemented for my type
问:
我正在创建一个更新系统。它在 2 个二进制文件之间创建补丁,压缩补丁和二进制文件并启动 Web 服务器。
我需要从闭包调用异步 fn。
所以闭包需要异步才能使用 fnawait
我愿意
let repair_stream = future::lazy(move |_| async {
let mut failures = {
let state = &mut *shared_state_r.borrow_mut();
state.previous_failures = mem::take(&mut state.failures);
state.previous_failures.clone()
};
if !failures.is_empty() {
failures.sort();
global_progression_r.lock().await.stage = UpdateStage::FindingRepairPath; // note the use of await
Either::Left(
update_internal(
update_options_r,
file_manager_r,
global_progression_r,
State::New, //< force to repair from no starting revision
shared_state_r,
repository,
goal_version_r,
UpdateFilter { failures },
UpdateStage::Repairing,
)
.try_flatten_stream(),
)
} else {
// nothing to repair, everything went well
Either::Right(stream::empty())
}
})
.flatten_stream();
但是得到
error[E0277]: the trait bound `impl futures::Future<Output = futures::future::Either<TryFlattenStream<impl futures::Future<Output = std::result::Result<impl futures::Stream<Item = std::result::Result<SharedUpdateProgress, UpdateError>> + '_, UpdateError>>>, futures::stream::Empty<_>>>: futures::Stream` is not satisfied
--> lib/src/workspace/updater.rs:342:25
|
342 | let repair_stream = future::lazy(move |_| async {
| _________________________^
343 | | let mut failures = {
344 | | let state = &mut *shared_state_r.borrow_mut();
345 | | state.previous_failures = mem::take(&mut state.failures);
... |
368 | | }
369 | | })
| |______^ the trait `futures::Stream` is not implemented for `impl futures::Future<Output = futures::future::Either<TryFlattenStream<impl futures::Future<Output = std::result::Result<impl futures::Stream<Item = std::result::Result<SharedUpdateProgress, UpdateError>> + '_, UpdateError>>>, futures::stream::Empty<_>>>`
370 | .flatten_stream();
| -------------- required by a bound introduced by this call
|
= help: the following other types implement trait `futures::Stream`:
&mut S
Abortable<St>
ApplyStream
AssertUnwindSafe<S>
Box<S>
Buffer<S, Item>
BufferUnordered<St>
Buffered<St>
and 84 others
note: required by a bound in `flatten_stream`
--> /home/runner/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-util-0.3.25/src/future/future/mod.rs:343:23
|
343 | Self::Output: Stream,
| ^^^^^^ required by this bound in `flatten_stream`
锁定 fn 返回tokio::sync::MutexGuard
完整来源: https://github.com/Ludea/speedupdate-rs/blob/master/lib/src/workspace/updater.rs#L342
我不明白这个问题,也不知道如何解决它
答: 暂无答案
评论
flatten_stream
Future
不是,也不是你为什么要尝试在最后一行调用,在我看来,你在这两种情况下得到的任何流首先都是“平坦”的‽Stream
Either
flatten_stream