Skip to content

Commit

Permalink
Improve docs for Templates
Browse files Browse the repository at this point in the history
  • Loading branch information
valebes committed Nov 8, 2023
1 parent ccf4516 commit 91930ab
Showing 1 changed file with 70 additions and 24 deletions.
94 changes: 70 additions & 24 deletions src/templates/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ where
{
/// Creates a new source from any type that implements the `Iterator` trait.
/// The source will terminate when the iterator is exhausted.
///
/// # Arguments
/// * `iterator` - Type that implements the [`Iterator`] trait
/// and represents the stream of data we want emit.
///
/// # Examples
///
Expand Down Expand Up @@ -63,8 +67,8 @@ where
T: Send + 'static,
{
/// Creates a new sink that accumulates data into a vector.
/// The sink will terminate when the upstream terminates.
/// The sink will produce a vector containing all the data received.
/// The sink will terminate when the stream terminates, producing
/// a vector containing all the data received.
///
/// # Examples
///
Expand Down Expand Up @@ -116,8 +120,10 @@ where
T: Send + 'static + Clone,
{
/// Creates a new splitter node.
/// The node will terminate when the upstream terminates.
///
/// # Arguments
/// * `chunk_size` - Number of elements for each chunk.
///
/// # Examples
/// Given a stream of numbers, we create a pipeline with a splitter that
/// create vectors of two elements each.
Expand All @@ -144,7 +150,10 @@ where
}

/// Creates a new splitter node with 'n_replicas' replicas of the same node.
/// The node will terminate when the upstream terminates.
///
/// # Arguments
/// * `n_replicas` - Number of replicas.
/// * `chunk_size` - Number of elements for each chunk.
pub fn build_with_replicas(n_replicas: usize, chunk_size: usize) -> impl InOut<Vec<T>, Vec<T>> {
Self {
chunk_size,
Expand Down Expand Up @@ -195,7 +204,9 @@ where
T: Send + 'static + Clone,
{
/// Creates a new aggregator node.
/// The node will terminate when the upstream terminates.
///
/// # Arguments
/// * `chunk_size` - Number of elements for each chunk.
///
/// # Examples
/// Given a stream of numbers, we use an [`Aggregator`] template to
Expand All @@ -221,7 +232,10 @@ where
}

/// Creates a new aggregator node with 'n_replicas' replicas of the same node.
/// The node will terminate when the upstream terminates.
///
/// # Arguments
/// * `n_replicas` - Number of replicas.
/// * `chunk_size` - Number of elements for each chunk.
pub fn build_with_replicas(n_replicas: usize, chunk_size: usize) -> impl InOut<T, Vec<T>> {

Check warning on line 239 in src/templates/misc.rs

View check run for this annotation

Codecov / codecov/patch

src/templates/misc.rs#L239

Added line #L239 was not covered by tests
Self {
chunk_size,
Expand Down Expand Up @@ -259,7 +273,7 @@ where

/// Sequential node.
///
/// Given a function that defines the logic of the stage, this method will create a stage with one replica.
/// Given a function that defines the logic of the node, this method will create a node with one replica.
#[derive(Clone)]
pub struct Sequential<T, U, F>
where
Expand All @@ -277,7 +291,10 @@ where
F: FnMut(T) -> U + Send + 'static + Clone,
{
/// Creates a new sequential node.
/// The node will terminate when the upstream terminates.
///
/// # Arguments
/// * `f` - Function name or lambda function that specify the logic
/// of this node.
pub fn build(f: F) -> impl InOut<T, U> {
Self {
f,
Expand All @@ -298,7 +315,7 @@ where

/// Parallel node.
///
/// Given a function that defines the logic of the stage, this method will create 'n_replicas' replicas of that stage.
/// Given a function that defines the logic of the node, this method will create 'n_replicas' replicas of that node.
#[derive(Clone)]
pub struct Parallel<T, U, F>
where
Expand All @@ -316,8 +333,12 @@ where
U: Send + 'static + Clone,
F: FnMut(T) -> U + Send + 'static + Clone,
{
/// Creates a new parallel node
/// The node will terminate when the upstream terminates.
/// Creates a new parallel node.
///
/// # Arguments
/// * `n_replicas` - Number of replicas.
/// * `f` - Function name or lambda function that specify the logic
/// of this node.
pub fn build(n_replicas: usize, f: F) -> impl InOut<T, U> {
Self {
n_replicas,
Expand Down Expand Up @@ -359,7 +380,10 @@ where
F: FnMut(&T) -> bool + Send + 'static + Clone,
{
/// Creates a new filter node.
/// The node will terminate when the upstream terminates.
///
/// # Arguments
/// * `f` - Function name or lambda function that represent the predicate
/// function we want to apply.
///
/// # Examples
/// Given a set of numbers from 0 to 199, we use a [`Filter`]
Expand All @@ -384,7 +408,11 @@ where
}
}
/// Creates a new filter node with 'n_replicas' replicas of the same node.
/// The node will terminate when the upstream terminates.
///
/// # Arguments
/// * `n_replicas` - Number of replicas.
/// * `f` - Function name or lambda function that represent the predicate
/// function we want to apply.
pub fn build_with_replicas(n_replicas: usize, f: F) -> impl InOut<T, T> {
Self {
f,
Expand Down Expand Up @@ -417,16 +445,17 @@ where
/// Sink node that accumulates data into a vector.
/// This is an ordered version of [`SinkVec`].
/// The sink will produce a vector containing all the data received in the same order
/// as it was received from the upstream.
/// as it was received.
pub struct OrderedSinkVec<T> {
data: Vec<T>,
}
impl<T> OrderedSinkVec<T>
where
T: Send + 'static,
{
/// Creates a new ordered sink that accumulates data into a vector.
/// The sink will terminate when the upstream terminates.
/// Creates a new sink that accumulates data into a vector.
/// The sink will terminate when the stream terminates, producing
/// a vector containing all the data received.
pub fn build() -> impl In<T, Vec<T>> {
Self { data: Vec::new() }
}
Expand Down Expand Up @@ -463,7 +492,8 @@ where
T: Send + 'static + Clone,
{
/// Creates a new ordered splitter node.
/// The node will terminate when the upstream terminates.
/// # Arguments
/// * `chunk_size` - Number of elements for each chunk.
pub fn build(chunk_size: usize) -> impl InOut<Vec<T>, Vec<T>> {
Self {
chunk_size,
Expand All @@ -473,7 +503,9 @@ where
}

/// Creates a new ordered splitter node with 'n_replicas' replicas of the same node.
/// The node will terminate when the upstream terminates.
/// # Arguments
/// * `n_replicas` - Number of replicas.
/// * `chunk_size` - Number of elements for each chunk.
pub fn build_with_replicas(n_replicas: usize, chunk_size: usize) -> impl InOut<Vec<T>, Vec<T>> {
Self {
chunk_size,
Expand Down Expand Up @@ -529,7 +561,9 @@ where
T: Send + 'static + Clone,
{
/// Creates a new ordered aggregator node
/// The node will terminate when the upstream terminates.
///
/// # Arguments
/// * `chunk_size` - Number of elements for each chunk.
pub fn build(chunk_size: usize) -> impl InOut<T, Vec<T>> {
Self {
chunk_size,
Expand All @@ -539,7 +573,9 @@ where
}

/// Creates a new ordered aggregator nod with 'n_replicas' replicas of the same node.
/// The node will terminate when the upstream terminates.
/// # Arguments
/// * `n_replicas` - Number of replicas.
/// * `chunk_size` - Number of elements for each chunk.
pub fn build_with_replicas(n_replicas: usize, chunk_size: usize) -> impl InOut<T, Vec<T>> {
Self {
chunk_size,
Expand Down Expand Up @@ -595,7 +631,9 @@ where
F: FnMut(T) -> U + Send + 'static + Clone,
{
/// Creates a new sequential node.
/// The node will terminate when the upstream terminates.
/// # Arguments
/// * `f` - Function name or lambda function that specify the logic
/// of this node.
pub fn build(f: F) -> impl InOut<T, U> {
Self {
f,
Expand Down Expand Up @@ -635,7 +673,10 @@ where
F: FnMut(T) -> U + Send + 'static + Clone,
{
/// Creates a new parallel node.
/// The node will terminate when the upstream terminates.
/// # Arguments
/// * `n_replicas` - Number of replicas.
/// * `f` - Function name or lambda function that specify the logic
/// of this node.
pub fn build(n_replicas: usize, f: F) -> impl InOut<T, U> {
Self {
f,
Expand Down Expand Up @@ -677,7 +718,9 @@ where
F: FnMut(&T) -> bool + Send + 'static + Clone,
{
/// Creates a new filter node.
/// The node will terminate when the upstream terminates.
/// # Arguments
/// * `f` - Function name or lambda function that represent the predicate
/// function we want to apply.
pub fn build(f: F) -> impl InOut<T, T> {
Self {
f,
Expand All @@ -686,7 +729,10 @@ where
}
}
/// Creates a new filter node.
/// The node will terminate when the upstream terminates.
/// # Arguments
/// * `n_replicas` - Number of replicas.
/// * `f` - Function name or lambda function that represent the predicate
/// function we want to apply.
pub fn build_with_replicas(n_replicas: usize, f: F) -> impl InOut<T, T> {
Self {
f,
Expand Down

0 comments on commit 91930ab

Please sign in to comment.