Julio Biason
6 months ago
4 changed files with 46 additions and 0 deletions
@ -0,0 +1,7 @@ |
|||||||
|
# This file is automatically @generated by Cargo. |
||||||
|
# It is not intended for manual editing. |
||||||
|
version = 3 |
||||||
|
|
||||||
|
[[package]] |
||||||
|
name = "abstractclasstest" |
||||||
|
version = "0.1.0" |
@ -0,0 +1,6 @@ |
|||||||
|
[package] |
||||||
|
name = "abstractclasstest" |
||||||
|
version = "0.1.0" |
||||||
|
edition = "2021" |
||||||
|
|
||||||
|
[dependencies] |
@ -0,0 +1,3 @@ |
|||||||
|
# AbstractClassTest |
||||||
|
|
||||||
|
Trying to do something akin to an abstract class in Rust. |
@ -0,0 +1,30 @@ |
|||||||
|
trait Base { |
||||||
|
fn files(&self) -> Vec<String>; |
||||||
|
fn show_files(&self) { |
||||||
|
for file in self.files() { |
||||||
|
println!("file={file}"); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
struct UpcaseFiles {} |
||||||
|
impl Base for UpcaseFiles { |
||||||
|
fn files(&self) -> Vec<String> { |
||||||
|
vec!["HELLO".into(), "WORLD".into()] |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
struct LowcaseFiles {} |
||||||
|
impl Base for LowcaseFiles { |
||||||
|
fn files(&self) -> Vec<String> { |
||||||
|
vec!["hello".into(), "world".into()] |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
fn main() { |
||||||
|
let f1 = UpcaseFiles {}; |
||||||
|
f1.show_files(); |
||||||
|
|
||||||
|
let f2 = LowcaseFiles {}; |
||||||
|
f2.show_files() |
||||||
|
} |
Loading…
Reference in new issue