eipw_lint/
fetch.rs

1/*
2 * This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at https://mozilla.org/MPL/2.0/.
5 */
6
7#[cfg(feature = "tokio")]
8pub mod tokio;
9
10use std::future::Future;
11use std::path::PathBuf;
12use std::pin::Pin;
13
14pub trait Fetch {
15    fn fetch(&self, path: PathBuf)
16        -> Pin<Box<dyn Future<Output = Result<String, std::io::Error>>>>;
17}
18
19#[derive(Debug, Default)]
20pub struct Null;
21
22impl Fetch for Null {
23    fn fetch(
24        &self,
25        _path: PathBuf,
26    ) -> Pin<Box<dyn Future<Output = Result<String, std::io::Error>>>> {
27        let fut = async { Err(std::io::ErrorKind::Unsupported.into()) };
28        Box::pin(fut)
29    }
30}
31
32#[cfg(feature = "tokio")]
33pub use self::tokio::Tokio as DefaultFetch;
34
35#[cfg(not(feature = "tokio"))]
36pub use self::Null as DefaultFetch;