-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathtrait_super.rs
More file actions
46 lines (36 loc) · 871 Bytes
/
Copy pathtrait_super.rs
File metadata and controls
46 lines (36 loc) · 871 Bytes
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
45
46
#![allow(unused)]
trait Language {
fn name(&self) -> String;
fn run(&self, file_path: &str) -> String;
}
trait Compiler {
fn compile(&self, file_path: &str) -> String;
}
trait CompiledLanguage: Language + Compiler {
fn exec(&self, file_path: &str) {
let cmd = self.compile(file_path);
println!("{cmd}");
let cmd = self.run(file_path);
println!("{cmd}");
}
}
struct Rust;
impl Language for Rust {
fn name(&self) -> String {
"Rust".to_string()
}
fn run(&self, file_path: &str) -> String {
format!("caro run {file_path}")
}
}
impl Compiler for Rust {
fn compile(&self, file_path: &str) -> String {
format!("cargo build {file_path}")
}
}
impl CompiledLanguage for Rust {}
fn main() {
let lang = Rust;
let file_path = "hello.rs";
lang.exec(file_path);
}