fn_graph/fn_wrapper.rs
1use std::{marker::PhantomData, ops::Deref};
2
3/// Wraps the graph `F` function type to upper bind the `'graph` lifetime to the
4/// `'iter` lifetime.
5///
6/// See:
7///
8/// * <https://users.rust-lang.org/t/102064>
9pub struct FnWrapper<'iter, 'graph: 'iter, F> {
10 /// The function stored in the graph.
11 f: &'iter F,
12 /// Marker.
13 marker: PhantomData<&'graph ()>,
14}
15
16impl<'iter, 'graph: 'iter, F> FnWrapper<'iter, 'graph, F> {
17 /// Returns a new `FnWrapper`.
18 pub(crate) fn new(f: &'iter F) -> Self {
19 Self {
20 f,
21 marker: PhantomData,
22 }
23 }
24}
25
26impl<F> Deref for FnWrapper<'_, '_, F> {
27 type Target = F;
28
29 fn deref(&self) -> &Self::Target {
30 self.f
31 }
32}