Advertisement
Guest User

Untitled

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