Created
November 13, 2020 01:26
-
-
Save jiacai2050/ea8ee1664dfe557cf2967e5019b8eca6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait Engine { | |
fn eval(&self) -> String; | |
} | |
struct JSEngine { | |
name: String, | |
} | |
impl JSEngine { | |
fn new(name: String) -> Self { | |
Self { name } | |
} | |
} | |
impl Engine for JSEngine { | |
fn eval(&self) -> String { | |
"js eval".to_string() | |
} | |
} | |
impl Drop for JSEngine { | |
fn drop(&mut self) { | |
println!("drop JSEngine {}", self.nam); | |
} | |
} | |
fn main() { | |
let x = "js eval".to_string(); | |
if x == JSEngine::new("abc".into()).eval() { | |
println!("inside {:?}", "if"); | |
} | |
println!("------------- {:?}", "sep"); | |
match JSEngine::new("abc".into()).eval() { | |
x => { | |
println!("inside {:?}", "match"); | |
} | |
_ => { | |
println!("not match {:?}", "here"); | |
} | |
} | |
println!("------------- {:?}", "sep"); | |
let s = JSEngine::new("last".into()).eval(); | |
println!("s {:?}", s); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment