indicator/context/extractor/
prev.rs1use crate::context::{layer::cache::Previous, ValueRef};
2
3use super::FromValueRef;
4
5pub struct Prev<T>(pub Option<T>);
7
8impl<'a, I, T> FromValueRef<'a, I> for Prev<&'a T>
9where
10 T: Send + Sync + 'static,
11{
12 #[inline]
13 fn from_value_ref(value: &ValueRef<'a, I>) -> Self {
14 Self(
15 value
16 .context
17 .env()
18 .get::<Previous>()
19 .expect(
20 "`Previous` not found in the context. Perhaps you forgot to add `Cache` layer?",
21 )
22 .get::<T>(),
23 )
24 }
25}