Advertisement
Guest User

Untitled

a guest
May 22nd, 2019
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. struct OutputBuilder<'a> {
  2. o: &'a mut Output,
  3. }
  4. struct DebugObject {}
  5. struct DebugOutput {}
  6.  
  7. trait Output {
  8. fn out(&mut self) -> OutputBuilder;
  9. }
  10.  
  11. trait Object {}
  12.  
  13. impl Object for DebugObject {}
  14.  
  15. impl DebugObject {
  16. fn new() -> Self {
  17. Self {}
  18. }
  19.  
  20. fn me() -> Self {
  21. Self {}
  22. }
  23. }
  24.  
  25. impl DebugOutput {
  26. fn new() -> Self {
  27. Self {}
  28. }
  29. }
  30.  
  31. impl<'a> OutputBuilder<'a> {
  32. fn new(o: &'a mut Output) -> Self {
  33. Self { o }
  34. }
  35.  
  36. fn a<'b, T: Object>(self, _obj: &'b T) -> Self {
  37. self
  38. }
  39. }
  40.  
  41. impl Output for DebugOutput {
  42. fn out(&mut self) -> OutputBuilder {
  43. OutputBuilder::new(self as &mut Output)
  44. }
  45. }
  46.  
  47. fn assert_call<'a, F>(func: F, _: &str)
  48. where
  49. F: for<'b> Fn(OutputBuilder<'a>, &'b DebugObject) -> OutputBuilder<'a>,
  50. {
  51. let mut out = DebugOutput::new();
  52. let me = DebugObject::me();
  53. let ob = out.out();
  54. func(ob, &me);
  55. }
  56.  
  57. fn main() {
  58. let f = OutputBuilder::a::<DebugObject>;
  59. assert_call(f, "xxx");
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement