Advertisement
Guest User

Untitled

a guest
Jul 17th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. use std::marker::PhantomData;
  2. use std::mem;
  3. use std::sync::Arc;
  4.  
  5. pub trait Database: Send + Sync + 'static {
  6. fn snapshot(&self) -> Box<dyn Snapshot>;
  7. }
  8.  
  9. trait Snapshot: 'static {
  10. fn foo(&self);
  11. }
  12.  
  13. struct DB {}
  14.  
  15. struct DBSnapshot<'a> {
  16. _lifetime: PhantomData<&'a ()>,
  17. }
  18.  
  19. impl DB {
  20. fn snapshot(&self) -> DBSnapshot {
  21. DBSnapshot {
  22. _lifetime: PhantomData,
  23. }
  24. }
  25. }
  26.  
  27. struct DBWrapper {
  28. db: Arc<DB>,
  29. }
  30.  
  31. impl Database for DBWrapper {
  32. fn snapshot(&self) -> Box<dyn Snapshot> {
  33. Box::new(DBWrapperSnapshot {
  34. snapshot: self.db.snapshot(),
  35. db: Arc::clone(&self.db),
  36. })
  37. }
  38. }
  39.  
  40. struct DBWrapperSnapshot {
  41. snapshot: DBSnapshot<'static>,
  42. db: Arc<DB>,
  43. }
  44.  
  45. impl Snapshot for DBWrapperSnapshot {
  46. fn foo(&self) {}
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement