feat: add tests
This commit is contained in:
26
__std/misc/src/bin/trait_struct_test.rs
Normal file
26
__std/misc/src/bin/trait_struct_test.rs
Normal file
@@ -0,0 +1,26 @@
|
||||
use std::ops::Deref;
|
||||
|
||||
trait WithName {
|
||||
fn get_name(&self) -> &str;
|
||||
}
|
||||
|
||||
struct Human {
|
||||
name: String,
|
||||
}
|
||||
|
||||
impl Human {
|
||||
fn new(name: String) -> Self {
|
||||
Self { name }
|
||||
}
|
||||
}
|
||||
|
||||
impl WithName for Human {
|
||||
fn get_name(&self) -> &str {
|
||||
self.name.deref()
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let with_name = Human::new("Hatter".into());
|
||||
println!("With name: {}", with_name.get_name());
|
||||
}
|
||||
Reference in New Issue
Block a user