Skip to content

Commit

Permalink
Add vec cache shortcut
Browse files Browse the repository at this point in the history
  • Loading branch information
imDema committed Oct 7, 2024
1 parent fceeb2e commit 1e044bc
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "renoir"
description = "Reactive Network of Operators In Rust"
version = "0.2.0"
version = "0.3.0"
edition = "2021"
authors = [
"Luca De Martini <[email protected]>",
Expand Down
23 changes: 22 additions & 1 deletion src/operator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::fmt::Display;
use std::hash::Hash;
use std::ops::{AddAssign, Div};

use cache::{CacheRegistry, CacheSink, CachedStream, Cacher};
use cache::{CacheRegistry, CacheSink, CachedStream, Cacher, VecCacher};
use flume::{unbounded, Receiver};
#[cfg(feature = "tokio")]
use futures::Future;
Expand Down Expand Up @@ -2120,6 +2120,14 @@ where
CachedStream::new(rt_config, replication, output)
}

/// Collect the output of the stream to a [StreamCache] that can later be resumed to
/// create a [Stream] with its content. Returns the cache and consumes the stream.
///
/// **See [Stream::collect_cache]**
pub fn collect_cache_vec(self) -> CachedStream<I, VecCacher<I>> {
self.collect_cache(())
}

/// Collect the output of the stream to a [StreamCache] that can later be resumed to
/// create a [Stream] with its content. Returns the cache and a copy of the current stream.
///
Expand Down Expand Up @@ -2168,6 +2176,19 @@ where
splits.pop().unwrap(),
)
}

/// Collect the output of the stream to a [StreamCache] that can later be resumed to
/// create a [Stream] with its content. Returns the cache and a copy of the current stream.
///
/// **See [Stream::cache]**
pub fn cache_vec(
self,
) -> (
CachedStream<I, VecCacher<I>>,
Stream<impl Operator<Out = Op::Out>>,
) {
self.cache(())
}
}

impl<Op> Stream<Op>
Expand Down

0 comments on commit 1e044bc

Please sign in to comment.