Skip to main content

spire_core/backend/
noop.rs

1use std::future::{Future, ready};
2
3use crate::Result;
4use crate::backend::{Backend, Session};
5use crate::http::{Request, Response};
6
7/// A backend whose client answers every request with an empty `200 OK`.
8///
9/// Useful for tests and examples that exercise the crawler without network
10/// access.
11#[derive(Debug, Clone, Copy, Default)]
12pub struct Noop;
13
14impl Backend for Noop {
15    type Session = Self;
16
17    fn connect(&self) -> impl Future<Output = Result<Self::Session>> + Send {
18        ready(Ok(Self))
19    }
20}
21
22impl Session for Noop {
23    fn fetch(&self, _request: &Request) -> impl Future<Output = Result<Response>> + Send {
24        ready(Ok(Response::default()))
25    }
26}