File: skip.rs

package info (click to toggle)
rust-transformation-pipeline 0.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 112 kB
  • sloc: makefile: 4
file content (44 lines) | stat: -rw-r--r-- 1,125 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
extern crate transformation_pipeline;

use transformation_pipeline::{TransformationStage, StageActions, StageResult, TransformationPipeline};

struct FirstTransformation {}

impl TransformationStage<String> for FirstTransformation {

    fn run(&self, _previous: String) -> StageResult<String> {
        Ok(StageActions::Next("a".to_owned()))
    }
}

struct SecondTransformation {}

impl TransformationStage<String> for SecondTransformation {

    fn run(&self, _previous: String) -> StageResult<String> {
        Ok(StageActions::Skip)
    }

}

struct ThirdTransformation {}

impl TransformationStage<String> for ThirdTransformation {

    fn run(&self, previous: String) -> StageResult<String> {
        assert_eq!(previous, "a".to_owned());
        Ok(StageActions::Next("b".to_owned()))
    }

}

#[test]
fn run_pipeline() {
    let pipeline: TransformationPipeline<String> = TransformationPipeline::new(vec![
        Box::new(FirstTransformation {}),
        Box::new(SecondTransformation {}),
        Box::new(ThirdTransformation {}),
    ]);

    assert_eq!(pipeline.run("z".to_owned()).unwrap(), "b".to_owned());
}