1#![allow(missing_docs)]
2
3use finchers_core::Endpoint;
4use finchers_core::endpoint::Context;
5use finchers_core::task;
6
7pub fn lazy<F, T>(f: F) -> Lazy<F>
12where
13 F: Fn(&mut Context) -> Option<T> + Send + Sync,
14 T: Send,
15{
16 Lazy { f }
17}
18
19#[derive(Debug, Clone, Copy)]
20pub struct Lazy<F> {
21 f: F,
22}
23
24impl<F, T> Endpoint for Lazy<F>
25where
26 F: Fn(&mut Context) -> Option<T> + Send + Sync,
27 T: Send,
28{
29 type Output = T;
30 type Task = task::Ready<T>;
31
32 fn apply(&self, cx: &mut Context) -> Option<Self::Task> {
33 (self.f)(cx).map(task::ready)
34 }
35}