Guest User

Untitled

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