Skip to content

Commit 8065c02

Browse files
committed
Get rid of one Gen::new, also clippy and stuff
1 parent 4b18802 commit 8065c02

File tree

4 files changed

+8
-42
lines changed

4 files changed

+8
-42
lines changed

src/api/blobs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -866,15 +866,15 @@ impl IrpcStreamItem for ListBlobsItem {
866866
fn into_result_opt(self) -> Option<Result<Hash, super::Error>> {
867867
match self {
868868
Self::Item(hash) => Some(Ok(hash)),
869-
Self::Error(e) => Some(Err(e.into())),
869+
Self::Error(e) => Some(Err(e)),
870870
Self::Done => None,
871871
}
872872
}
873873

874874
fn from_result(item: std::result::Result<Hash, super::Error>) -> Self {
875875
match item {
876876
Ok(hash) => Self::Item(hash),
877-
Err(e) => Self::Error(e.into()),
877+
Err(e) => Self::Error(e),
878878
}
879879
}
880880

src/api/proto.rs

Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ use bao_tree::{
2929
ChunkRanges,
3030
};
3131
use bytes::Bytes;
32-
use genawaiter::sync::Gen;
3332
use irpc::{
3433
channel::{mpsc, oneshot},
3534
rpc_requests,
@@ -398,7 +397,7 @@ impl IrpcStreamItem for ListTagsItem {
398397
fn from_result(item: std::result::Result<TagInfo, super::Error>) -> Self {
399398
match item {
400399
Ok(i) => Self::Item(i),
401-
Err(e) => Self::Error(e.into()),
400+
Err(e) => Self::Error(e),
402401
}
403402
}
404403

@@ -431,41 +430,7 @@ impl ListTagsProgress {
431430
}
432431

433432
pub fn stream(self) -> impl Stream<Item = super::Result<TagInfo>> {
434-
Gen::new(|co| async move {
435-
let mut rx = match self.inner.await {
436-
Ok(rx) => rx,
437-
Err(err) => {
438-
co.yield_(Err(super::Error::from(err))).await;
439-
return;
440-
}
441-
};
442-
loop {
443-
match rx.recv().await {
444-
Ok(Some(ListTagsItem::Item(item))) => {
445-
co.yield_(Ok(item)).await;
446-
}
447-
Ok(Some(ListTagsItem::Done)) => {
448-
break;
449-
}
450-
Ok(Some(ListTagsItem::Error(err))) => {
451-
co.yield_(Err(err.into())).await;
452-
break;
453-
}
454-
Ok(None) => {
455-
co.yield_(Err(super::Error::Io(io::Error::new(
456-
io::ErrorKind::UnexpectedEof,
457-
"stream ended",
458-
))))
459-
.await;
460-
break;
461-
}
462-
Err(cause) => {
463-
co.yield_(Err(super::Error::from(cause))).await;
464-
break;
465-
}
466-
}
467-
}
468-
})
433+
self.inner.into_stream()
469434
}
470435
}
471436

src/store/readonly_mem.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ use crate::{
4242
ApiClient, TempTag,
4343
},
4444
store::{mem::CompleteStorage, IROH_BLOCK_SIZE},
45-
util::ChunkRangesExt,
45+
util::{irpc::MpscSenderExt, ChunkRangesExt},
4646
Hash,
4747
};
4848

@@ -196,7 +196,7 @@ impl Actor {
196196
cmd.tx.send(status).await.ok();
197197
}
198198
Command::ListTags(cmd) => {
199-
cmd.tx.send(proto::ListTagsItem::Done).await.ok();
199+
cmd.tx.forward_iter(std::iter::empty()).await.ok();
200200
}
201201
Command::SetTag(cmd) => {
202202
cmd.tx

src/util/irpc.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ pub(crate) trait MpscSenderExt<T: IrpcStreamItem>: Sized {
2929
///
3030
/// This will convert items and errors into the item enum type, and add
3131
/// a done marker if the stream ends without an error.
32+
#[allow(dead_code)]
3233
async fn forward_stream(
3334
self,
3435
stream: impl Stream<Item = std::result::Result<T::Item, T::Error>>,
@@ -122,7 +123,7 @@ where
122123
while let Some(item) = stream.next().await {
123124
match item {
124125
Ok(i) => items.extend(Some(i)),
125-
Err(e) => return Err(E::from(e)),
126+
Err(e) => return Err(e),
126127
}
127128
}
128129
Ok(items)

0 commit comments

Comments
 (0)