Skip to content

Instantly share code, notes, and snippets.

@matthauck
Created March 23, 2020 18:55
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 matthauck/9743152133266c50d5593a90867b34c1 to your computer and use it in GitHub Desktop.
Save matthauck/9743152133266c50d5593a90867b34c1 to your computer and use it in GitHub Desktop.
async-trait, issue #75
[package]
name = "async-trait-75"
version = "0.1.0"
authors = []
edition = "2018"
[dependencies]
async-trait = "0.1.17"
tokio = { version = "0.2.13", features = [ "rt-threaded", "macros" ] }
$ cargo build
Compiling async-trait-75 v0.1.0 (/Users/user/async-trait-test)
warning: unused implementer of `std::future::Future` that must be used
--> src/main.rs:26:5
|
26 | thing.do_direct();
| ^^^^^^^^^^^^^^^^^^
|
= note: `#[warn(unused_must_use)]` on by default
= note: futures do nothing unless you `.await` or poll them
Finished dev [unoptimized + debuginfo] target(s) in 1.35s
#[async_trait::async_trait]
trait Interface {
async fn do_trait(&self);
}
struct Thing;
#[async_trait::async_trait]
impl Interface for Thing {
async fn do_trait(&self) {
println!("hello from trait");
}
}
impl Thing {
async fn do_direct(&self) {
println!("hello from direct");
}
}
#[tokio::main]
async fn main() {
let thing = Thing {};
thing.do_trait();
thing.do_direct();
}
@matthauck
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment