Advertisement
Guest User

Untitled

a guest
Sep 16th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. trait Diffable<'a> {
  2. type D: 'a;
  3.  
  4. fn diff(&'a self) -> Self::D;
  5. }
  6.  
  7. struct Edit<'a, T> {
  8. marker: std::marker::PhantomData<&'a T>,
  9. }
  10.  
  11. impl<'a, T> Edit<'a, T> {
  12. fn new(value: &'a T) -> Self {
  13. Self {
  14. marker: std::marker::PhantomData,
  15. }
  16. }
  17. }
  18.  
  19. //#[derive(Diffus)]
  20. struct Foo {
  21. x: String,
  22. y: i32,
  23. }
  24.  
  25. // Generated by derive(Diffus)
  26. struct EditedFoo<'a> {
  27. x: Edit<'a, String>,
  28. y: Edit<'a, i32>,
  29. }
  30.  
  31. // Generated by derive(Diffus)
  32. impl<'a> Diffable<'a> for Foo {
  33. type D = EditedFoo<'a>;
  34.  
  35. fn diff(&'a self) -> Self::D {
  36. EditedFoo {
  37. x: Edit::new(&self.x),
  38. y: Edit::new(&self.y),
  39. }
  40. }
  41. }
  42.  
  43. fn main() {
  44.  
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement