|
14 | 14 | //! The file system store is quite complex and optimized, so to get started take a look at |
15 | 15 | //! the much simpler memory store. |
16 | 16 | use std::{ |
| 17 | + collections::HashSet, |
17 | 18 | fmt::{self, Debug}, |
18 | 19 | future::{Future, IntoFuture}, |
19 | 20 | io, |
@@ -131,7 +132,7 @@ pub enum Request { |
131 | 132 | RenameTag(RenameTagRequest), |
132 | 133 | #[rpc(tx = oneshot::Sender<super::Result<Tag>>)] |
133 | 134 | CreateTag(CreateTagRequest), |
134 | | - #[rpc(tx = oneshot::Sender<Vec<HashAndFormat>>)] |
| 135 | + #[rpc(tx = mpsc::Sender<ListTempTagsItem>)] |
135 | 136 | ListTempTags(ListTempTagsRequest), |
136 | 137 | #[rpc(tx = oneshot::Sender<TempTag>)] |
137 | 138 | CreateTempTag(CreateTempTagRequest), |
@@ -406,6 +407,34 @@ impl IrpcStreamItem for ListTagsItem { |
406 | 407 | } |
407 | 408 | } |
408 | 409 |
|
| 410 | +pub struct ListTempTagsProgress { |
| 411 | + inner: future::Boxed<irpc::Result<mpsc::Receiver<ListTempTagsItem>>>, |
| 412 | +} |
| 413 | + |
| 414 | +impl IntoFuture for ListTempTagsProgress { |
| 415 | + fn into_future(self) -> Self::IntoFuture { |
| 416 | + Box::pin(self.inner.try_collect()) |
| 417 | + } |
| 418 | + |
| 419 | + type IntoFuture = future::Boxed<Self::Output>; |
| 420 | + |
| 421 | + type Output = super::Result<HashSet<HashAndFormat>>; |
| 422 | +} |
| 423 | + |
| 424 | +impl ListTempTagsProgress { |
| 425 | + pub(super) fn new( |
| 426 | + fut: impl Future<Output = irpc::Result<mpsc::Receiver<ListTempTagsItem>>> + Send + 'static, |
| 427 | + ) -> Self { |
| 428 | + Self { |
| 429 | + inner: Box::pin(fut), |
| 430 | + } |
| 431 | + } |
| 432 | + |
| 433 | + pub fn stream(self) -> impl Stream<Item = super::Result<HashAndFormat>> { |
| 434 | + self.inner.into_stream() |
| 435 | + } |
| 436 | +} |
| 437 | + |
409 | 438 | pub struct ListTagsProgress { |
410 | 439 | inner: future::Boxed<irpc::Result<mpsc::Receiver<ListTagsItem>>>, |
411 | 440 | } |
@@ -493,6 +522,37 @@ pub struct CreateTempTagRequest { |
493 | 522 | #[derive(Debug, Serialize, Deserialize)] |
494 | 523 | pub struct ListTempTagsRequest; |
495 | 524 |
|
| 525 | +#[derive(Debug, Serialize, Deserialize)] |
| 526 | +pub enum ListTempTagsItem { |
| 527 | + Item(HashAndFormat), |
| 528 | + Error(super::Error), |
| 529 | + Done, |
| 530 | +} |
| 531 | + |
| 532 | +impl IrpcStreamItem for ListTempTagsItem { |
| 533 | + type Error = super::Error; |
| 534 | + type Item = HashAndFormat; |
| 535 | + |
| 536 | + fn into_result_opt(self) -> Option<Result<HashAndFormat, super::Error>> { |
| 537 | + match self { |
| 538 | + ListTempTagsItem::Item(item) => Some(Ok(item)), |
| 539 | + ListTempTagsItem::Done => None, |
| 540 | + ListTempTagsItem::Error(err) => Some(Err(err)), |
| 541 | + } |
| 542 | + } |
| 543 | + |
| 544 | + fn from_result(item: std::result::Result<HashAndFormat, super::Error>) -> Self { |
| 545 | + match item { |
| 546 | + Ok(i) => Self::Item(i), |
| 547 | + Err(e) => Self::Error(e), |
| 548 | + } |
| 549 | + } |
| 550 | + |
| 551 | + fn done() -> Self { |
| 552 | + Self::Done |
| 553 | + } |
| 554 | +} |
| 555 | + |
496 | 556 | /// Rename a tag atomically |
497 | 557 | #[derive(Debug, Serialize, Deserialize)] |
498 | 558 | pub struct RenameTagRequest { |
|
0 commit comments