use super::BoxFuture;
use super::ServiceRef;
use super::model_ref::ref_conversions;
use crate::error::ProviderError;
use crate::files::DeleteFileResult;
use crate::files::DownloadFileResult;
use crate::files::FileMetadataResult;
use crate::files::FileReferenceOptions;
use crate::files::Files;
use crate::files::UploadFileOptions;
use crate::files::UploadFileResult;
use crate::shared::ProviderId;
pub trait DynFiles: Send + Sync + 'static {
fn provider(&self) -> &ProviderId;
fn upload_file(
&self,
options: UploadFileOptions,
) -> BoxFuture<'_, Result<UploadFileResult, ProviderError>>;
fn supports_get_file_metadata(&self) -> bool;
fn get_file_metadata(
&self,
options: FileReferenceOptions,
) -> BoxFuture<'_, Result<FileMetadataResult, ProviderError>>;
fn supports_download_file(&self) -> bool;
fn download_file(
&self,
options: FileReferenceOptions,
) -> BoxFuture<'_, Result<DownloadFileResult, ProviderError>>;
fn supports_delete_file(&self) -> bool;
fn delete_file(
&self,
options: FileReferenceOptions,
) -> BoxFuture<'_, Result<DeleteFileResult, ProviderError>>;
}
impl<T: Files> DynFiles for T {
fn provider(&self) -> &ProviderId {
Files::provider(self)
}
fn upload_file(
&self,
options: UploadFileOptions,
) -> BoxFuture<'_, Result<UploadFileResult, ProviderError>> {
Box::pin(Files::upload_file(self, options))
}
fn supports_get_file_metadata(&self) -> bool {
Files::supports_get_file_metadata(self)
}
fn get_file_metadata(
&self,
options: FileReferenceOptions,
) -> BoxFuture<'_, Result<FileMetadataResult, ProviderError>> {
Box::pin(Files::get_file_metadata(self, options))
}
fn supports_download_file(&self) -> bool {
Files::supports_download_file(self)
}
fn download_file(
&self,
options: FileReferenceOptions,
) -> BoxFuture<'_, Result<DownloadFileResult, ProviderError>> {
Box::pin(Files::download_file(self, options))
}
fn supports_delete_file(&self) -> bool {
Files::supports_delete_file(self)
}
fn delete_file(
&self,
options: FileReferenceOptions,
) -> BoxFuture<'_, Result<DeleteFileResult, ProviderError>> {
Box::pin(Files::delete_file(self, options))
}
}
pub type FilesRef = ServiceRef<dyn DynFiles>;
ref_conversions!(FilesRef, Files, DynFiles);