finchers_ext/
just.rs

1use finchers_core::Endpoint;
2use finchers_core::endpoint::Context;
3use finchers_core::task;
4
5/// Create an endpoint which immediately returns a value of `T`.
6pub fn just<T>(x: T) -> Just<T>
7where
8    T: Clone + Send + Sync,
9{
10    Just { x }
11}
12
13#[allow(missing_docs)]
14#[derive(Debug, Clone, Copy)]
15pub struct Just<T> {
16    x: T,
17}
18
19impl<T> Endpoint for Just<T>
20where
21    T: Clone + Send + Sync,
22{
23    type Output = T;
24    type Task = task::Ready<T>;
25
26    fn apply(&self, _: &mut Context) -> Option<Self::Task> {
27        Some(task::ready(self.x.clone()))
28    }
29}