use std::fmt;
pub trait Loader: Sized + std::fmt::Debug {
type File: std::io::Read;
fn find_file(&self, url: &str) -> Result<Option<Self::File>, LoadError>;
}
#[non_exhaustive]
#[derive(Debug)]
pub enum LoadError {
Input(String, std::io::Error),
UnknownFormat(String),
NotCalledFromCargo,
}
impl std::error::Error for LoadError {}
impl fmt::Display for LoadError {
fn fmt(&self, out: &mut fmt::Formatter) -> fmt::Result {
match self {
Self::Input(path, err) => {
write!(out, "Reading {path:?} failed: {err}")
}
Self::UnknownFormat(name) => {
write!(out, "{name:?} is not a css or sass file.")
}
Self::NotCalledFromCargo => {
write!(out, "Expected a cargo environment, but none found.")
}
}
}
}