Skip to content

Instantly share code, notes, and snippets.

@jiacai2050
Created November 13, 2020 01:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jiacai2050/ea8ee1664dfe557cf2967e5019b8eca6 to your computer and use it in GitHub Desktop.
Save jiacai2050/ea8ee1664dfe557cf2967e5019b8eca6 to your computer and use it in GitHub Desktop.
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