use base_scheduler::Cancellation;
use base_web_content::UploadHead;
use std::{error::Error, fmt, future::Future};
pub trait UploadStore: Send {
type Handle: Send;
type Upload: Send;
type Error: Error + Send + Sync + 'static;
fn create(
&mut self,
head: &UploadHead,
cancellation: &Cancellation,
) -> impl Future<Output = Result<Self::Upload, Self::Error>> + Send;
fn write(
&mut self,
upload: &mut Self::Upload,
content: &[u8],
cancellation: &Cancellation,
) -> impl Future<Output = Result<(), Self::Error>> + Send;
fn finish(
&mut self,
upload: &mut Self::Upload,
cancellation: &Cancellation,
) -> impl Future<Output = Result<Self::Handle, Self::Error>> + Send;
fn abort(
&mut self,
upload: Self::Upload,
) -> impl Future<Output = Result<(), Self::Error>> + Send;
fn remove(
&mut self,
handle: Self::Handle,
) -> impl Future<Output = Result<(), Self::Error>> + Send;
}
#[derive(Clone, Copy, Debug, Default)]
pub struct NoUploads;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct NoUploadsError;
impl fmt::Display for NoUploadsError {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
formatter.write_str("no store was given for uploads")
}
}
impl Error for NoUploadsError {}
impl UploadStore for NoUploads {
type Handle = ();
type Upload = ();
type Error = NoUploadsError;
async fn create(&mut self, _: &UploadHead, _: &Cancellation) -> Result<(), NoUploadsError> {
Err(NoUploadsError)
}
async fn write(
&mut self,
_: &mut (),
_: &[u8],
_: &Cancellation,
) -> Result<(), NoUploadsError> {
Err(NoUploadsError)
}
async fn finish(&mut self, _: &mut (), _: &Cancellation) -> Result<(), NoUploadsError> {
Err(NoUploadsError)
}
async fn abort(&mut self, _: ()) -> Result<(), NoUploadsError> {
Ok(())
}
async fn remove(&mut self, _: ()) -> Result<(), NoUploadsError> {
Ok(())
}
}