Advertisement
Guest User

Untitled

a guest
Mar 25th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. #![feature(nll)]
  2.  
  3. trait DebugWith<Cx: ?Sized> {
  4. fn debug_with<'me>(&'me self, cx: &'me Cx) -> DebugCxPair<'me, Self, Cx> {
  5. DebugCxPair { value: self, cx }
  6. }
  7.  
  8. fn fmt_with(&self, _cx: &Cx, _fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result;
  9. }
  10.  
  11. struct DebugCxPair<'me, Value: ?Sized, Cx: ?Sized>
  12. where
  13. Value: DebugWith<Cx>,
  14. {
  15. value: &'me Value,
  16. cx: &'me Cx,
  17. }
  18.  
  19. trait DebugContext { }
  20.  
  21. struct Foo {
  22. bar: Bar
  23. }
  24.  
  25. impl DebugWith<dyn DebugContext> for Foo {
  26. fn fmt_with(&self, cx: &dyn DebugContext, _fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
  27. let Foo { bar } = self;
  28. bar.debug_with(cx);
  29. Ok(())
  30. }
  31. }
  32.  
  33. struct Bar { }
  34.  
  35. impl DebugWith<dyn DebugContext> for Bar {
  36. fn fmt_with(&self, _cx: &dyn DebugContext, _fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
  37. Ok(())
  38. }
  39. }
  40.  
  41. fn main() { }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement