Skip to content

Instantly share code, notes, and snippets.

@satellitex
Created April 20, 2019 05:15
Show Gist options
  • Save satellitex/18d12c236a0ba2076183c115d244c59d to your computer and use it in GitHub Desktop.
Save satellitex/18d12c236a0ba2076183c115d244c59d to your computer and use it in GitHub Desktop.
Trait を static 構造体みたいに使う。
pub trait Trait<T: std::fmt::Debug> {
fn display(&self, t: T) {
println!("{:?}", t);
}
}
pub struct Dummy;
impl<T: std::fmt::Debug> Trait<T> for Dummy{}
fn main() {
<Trait<i32>>::display(&Dummy, 1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment