-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
U cannot get this to work. It's close but I think it requires lifetime bounds on the HRTB lifetimes e.g. `F: for<'a, 'store: 'a> ...`, which currently isn't possible (seems to have been possible at one point? rust-lang/rust#50555 Could also be just that the syntax didn't result in an error, but had no semantic meaning attached to it.)
- Loading branch information
1 parent
72fd009
commit 7e6e585
Showing
7 changed files
with
113 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
use std::sync::atomic::AtomicU64; | ||
use std::marker; | ||
use crate::TypeConstructor; | ||
use crate::store::{ReadContext, Store}; | ||
use crate::versioned_cell::VersionedCell; | ||
use crate::memo::{Memo, Refresh, Selector}; | ||
use std::sync::atomic; | ||
|
||
pub struct OwnedMemo<C, S, T> { | ||
select: S, | ||
store_id: u64, | ||
last: T, | ||
_marker: marker::PhantomData<*const C>, | ||
} | ||
|
||
impl<C, S, T> OwnedMemo<C, S, T> | ||
where | ||
C: TypeConstructor, | ||
S: for<'a, 'store> Fn(&'a C::Type<'store>, ReadContext<'store>) -> T, | ||
{ | ||
pub fn new(store: &Store<C>, select: S) -> Self { | ||
let last = store.with(|root, cx| select(root, cx)); | ||
|
||
OwnedMemo { | ||
select, | ||
store_id: store.id(), | ||
last, | ||
_marker: marker::PhantomData, | ||
} | ||
} | ||
} | ||
|
||
// impl<C, S, T> Memo for OwnedMemo<C, S> | ||
// where | ||
// C: TypeConstructor, | ||
// S: for<'a, 'store> Fn(&'a C::Type<'store>, ReadContext<'store>) -> &'a VersionedCell<'store, T> | ||
// + Clone, | ||
// { | ||
// type RootTC = C; | ||
// type Target<'store> = VersionedCell<'store, T>; | ||
// type Selector = CellSelector<C, S>; | ||
// | ||
// fn refresh<'a, 'store>( | ||
// &mut self, | ||
// root: &'a C::Type<'store>, | ||
// cx: ReadContext<'store>, | ||
// ) -> Refresh<&'a Self::Target<'store>> { | ||
// if cx.store_id() != self.store_id { | ||
// panic!("cannot resolve selector against different store") | ||
// } | ||
// | ||
// let cell = (self.select)(root, cx); | ||
// let version = cell.version(); | ||
// let last_version = self.last_version; | ||
// | ||
// self.last_version = version; | ||
// | ||
// if version == last_version { | ||
// Refresh::Unchanged(cell) | ||
// } else { | ||
// Refresh::Changed(cell) | ||
// } | ||
// } | ||
// | ||
// fn selector(&self) -> Self::Selector { | ||
// CellSelector { | ||
// lens: self.select.clone(), | ||
// _marker: marker::PhantomData, | ||
// } | ||
// } | ||
// } | ||
|
||
pub struct OwnedSelector<C, T> { | ||
value: T, | ||
_marker: marker::PhantomData<*const C> | ||
} | ||
|
||
impl<C, T> Selector for OwnedSelector<C, T> where C: TypeConstructor, T: Clone { | ||
type RootTC = C; | ||
type Target<'a, 'store: 'a> = T; | ||
|
||
fn select<'a, 'store: 'a>( | ||
&self, | ||
root: &'a C::Type<'store>, | ||
cx: ReadContext<'store>, | ||
) -> T { | ||
self.value.clone() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters