Skip to content

Instantly share code, notes, and snippets.

@ilopX
Created August 2, 2022 08:57
Show Gist options
  • Select an option

  • Save ilopX/f0d3893b3049a988270068c364963e7c to your computer and use it in GitHub Desktop.

Select an option

Save ilopX/f0d3893b3049a988270068c364963e7c to your computer and use it in GitHub Desktop.
fn main() {
CvsMiner.mine("file.cvs");
TxtMiner.mine("file.txt");
}
trait Miner {
fn mine(&self, file_name: &str) {
let file = self.open_file(file_name);
let raw = self.extract_data(file);
let table = self.parse_data(raw);
let analysis = self.analyze_data(&table);
self.send_report(analysis, table);
}
fn open_file(&self, file_name: &str) -> () {
println!("open_file {}", file_name);
}
fn extract_data(&self, file: ()) -> String {
println!("extract data");
"".into()
}
fn parse_data(&self, raw: String) -> ();
fn analyze_data(&self, table: &()) -> () {
println!("analyze_data");
}
fn send_report(&self, analysis: (), table: ()) {
println!("send_report\n");
}
}
struct CvsMiner;
impl Miner for CvsMiner {
fn parse_data(&self, raw: String) -> () {
println!("mine Cvs");
}
}
struct TxtMiner;
impl Miner for TxtMiner {
fn parse_data(&self, raw: String) -> () {
println!("mine Txt");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment