Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use std::marker::PhantomData;
- use std::mem;
- use std::sync::Arc;
- pub trait Database: Send + Sync + 'static {
- fn snapshot(&self) -> Box<dyn Snapshot>;
- }
- trait Snapshot: 'static {
- fn foo(&self);
- }
- struct DB {}
- struct DBSnapshot<'a> {
- _lifetime: PhantomData<&'a ()>,
- }
- impl DB {
- fn snapshot(&self) -> DBSnapshot {
- DBSnapshot {
- _lifetime: PhantomData,
- }
- }
- }
- struct DBWrapper {
- db: Arc<DB>,
- }
- impl Database for DBWrapper {
- fn snapshot(&self) -> Box<dyn Snapshot> {
- Box::new(DBWrapperSnapshot {
- snapshot: self.db.snapshot(),
- db: Arc::clone(&self.db),
- })
- }
- }
- struct DBWrapperSnapshot {
- snapshot: DBSnapshot<'static>,
- db: Arc<DB>,
- }
- impl Snapshot for DBWrapperSnapshot {
- fn foo(&self) {}
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement