Skip to content

Instantly share code, notes, and snippets.

@jayendra13
Created April 6, 2022 11:33
Show Gist options
  • Save jayendra13/2e12822827a4f758865316d6d42dc9a7 to your computer and use it in GitHub Desktop.
Save jayendra13/2e12822827a4f758865316d6d42dc9a7 to your computer and use it in GitHub Desktop.
#[derive(Debug)]
struct Pipeline {
context: String,
}
impl Pipeline {
fn new(context: String) -> Pipeline {
Pipeline {
context: context,
}
}
fn apply_transform(&self, transform: &impl PTransform, input: &impl PValue) -> PCollection {
transform.expand(input)
}
}
trait PTransform {
fn expand(&self, input: &impl PValue) -> PCollection;
}
#[derive(Debug)]
struct Impulse {
}
impl Impulse {
fn new() -> Impulse {
Impulse {}
}
}
impl PTransform for Impulse {
fn expand(&self, input: &impl PValue) -> PCollection {
PCollection{}
}
}
trait PValue {
fn apply(self, transform: &impl PTransform) -> PCollection;
}
#[derive(Debug)]
struct Root<'a> {
pipeline: &'a Pipeline,
}
impl<'a> Root<'a> {
fn new(pipeline: &'a Pipeline) -> Root {
Root {
pipeline: pipeline,
}
}
}
impl<'a> PValue for Root<'a> {
fn apply(self, transform: &impl PTransform) -> PCollection {
self.pipeline.apply_transform(transform, &self)
}
}
#[derive(Debug)]
struct PCollection {}
impl PCollection {
fn new() -> PCollection {
PCollection {}
}
}
fn main() {
let p = Pipeline::new("context".to_string());
println!("{:?}", p);
// let root = Root::new(&p);
// println!("{:?}", root);
// let impulse = Impulse::new();
// println!("{:?}", impulse);
// let res = root.apply(&impulse);
// println!("{:?}", res);
let res = Root::new(&p).apply(&Impulse::new());
println!("{:?}", res);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment