Guest User

Untitled

a guest
Jul 19th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. use std::marker::PhantomData;
  2.  
  3. struct Bar<S> {
  4. phantom: PhantomData<S>,
  5. }
  6.  
  7. impl<S> Bar<S>
  8. where
  9. S: Foo,
  10. {
  11. fn new() -> Self {
  12. Bar {phantom: PhantomData}
  13. }
  14.  
  15. fn foo_method(&self) {
  16. S::new().do_stuff();
  17. }
  18. }
  19.  
  20. trait Foo {
  21. fn new() -> Self;
  22. fn do_stuff(&self);
  23. }
  24.  
  25. struct FooA<'a> {
  26. _data: &'a str,
  27. }
  28.  
  29. impl<'a> Foo for FooA<'a> {
  30. fn new() -> FooA<'a> {
  31. FooA {
  32. _data: "",
  33. }
  34. }
  35.  
  36. fn do_stuff(&self) {}
  37. }
  38.  
  39. fn main() {
  40. Bar::<FooA>::new().foo_method();
  41. }
Add Comment
Please, Sign In to add comment