use crate::error::Error;
use crate::source::Format;
#[derive(Clone, PartialEq, Eq)]
pub struct Fetched {
pub text: String,
pub format: Format,
}
impl Fetched {
#[must_use]
pub fn new(text: impl Into<String>, format: Format) -> Self {
Self {
text: text.into(),
format,
}
}
}
impl std::fmt::Debug for Fetched {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Fetched")
.field("format", &self.format)
.field("bytes", &self.text.len())
.finish()
}
}
pub trait RemoteSource: Send + Sync + 'static {
fn fetch(&self) -> Result<Fetched, Error>;
fn describe(&self) -> String;
}
#[cfg(feature = "async")]
#[cfg_attr(docsrs, doc(cfg(feature = "async")))]
pub trait AsyncRemoteSource: Send + Sync + 'static {
fn fetch(
&self,
) -> std::pin::Pin<Box<dyn std::future::Future<Output = Result<Fetched, Error>> + Send + '_>>;
fn describe(&self) -> String;
}