diff options
author | Vika <vika@fireburn.ru> | 2024-08-26 20:25:20 +0300 |
---|---|---|
committer | Vika <vika@fireburn.ru> | 2024-08-26 20:25:20 +0300 |
commit | 806f5fbfabd914d27ff3fb2e822e1c3869068859 (patch) | |
tree | cc805cfb7ef5af3d7e26075106d2663e5ca2dd67 /src/media | |
parent | 14e58b4137f8f77af43cad8b712596c2e1ab7e8a (diff) | |
download | kittybox-806f5fbfabd914d27ff3fb2e822e1c3869068859.tar.zst |
Set MSRV to 1.75, remove #[async_trait] declarations whenever possible
Axum still uses `async_trait`, let them do whatever they want. I will no longer be subject to the humiliation of trying to dig through lifetime errors and unreadable declarations. Also I don't fucking care about MSRV, I'm not a library. If you don't have modern Rust, get one.
Diffstat (limited to 'src/media')
-rw-r--r-- | src/media/storage/file.rs | 2 | ||||
-rw-r--r-- | src/media/storage/mod.rs | 28 |
2 files changed, 15 insertions, 15 deletions
diff --git a/src/media/storage/file.rs b/src/media/storage/file.rs index b9ab541..711b298 100644 --- a/src/media/storage/file.rs +++ b/src/media/storage/file.rs @@ -1,5 +1,4 @@ use super::{Metadata, ErrorKind, MediaStore, MediaStoreError, Result}; -use async_trait::async_trait; use std::{path::PathBuf, fmt::Debug}; use tokio::fs::OpenOptions; use tokio::io::{BufReader, BufWriter, AsyncWriteExt, AsyncSeekExt}; @@ -39,7 +38,6 @@ impl FileStore { } } -#[async_trait] impl MediaStore for FileStore { async fn new(url: &'_ url::Url) -> Result<Self> { Ok(Self { base: url.path().into() }) diff --git a/src/media/storage/mod.rs b/src/media/storage/mod.rs index 38410e6..c2a66ec 100644 --- a/src/media/storage/mod.rs +++ b/src/media/storage/mod.rs @@ -1,8 +1,8 @@ -use async_trait::async_trait; use axum::extract::multipart::Field; use tokio_stream::Stream; use bytes::Bytes; use serde::{Deserialize, Serialize}; +use std::future::Future; use std::ops::Bound; use std::pin::Pin; use std::fmt::Debug; @@ -84,31 +84,33 @@ impl std::fmt::Display for MediaStoreError { pub type Result<T> = std::result::Result<T, MediaStoreError>; -#[async_trait] pub trait MediaStore: 'static + Send + Sync + Clone { // Initialize self from a URL, possibly performing asynchronous initialization. - async fn new(url: &'_ url::Url) -> Result<Self>; - async fn write_streaming<T>( + fn new(url: &'_ url::Url) -> impl Future<Output = Result<Self>> + Send; + + fn write_streaming<T>( &self, domain: &str, metadata: Metadata, content: T, - ) -> Result<String> + ) -> impl Future<Output = Result<String>> + Send where T: tokio_stream::Stream<Item = std::result::Result<bytes::Bytes, axum::extract::multipart::MultipartError>> + Unpin + Send + Debug; - async fn read_streaming( + fn read_streaming( &self, domain: &str, filename: &str, - ) -> Result<(Metadata, Pin<Box<dyn Stream<Item = std::io::Result<Bytes>> + Send>>)>; + ) -> impl Future<Output = Result< + (Metadata, Pin<Box<dyn Stream<Item = std::io::Result<Bytes>> + Send>>) + >> + Send; - async fn stream_range( + fn stream_range( &self, domain: &str, filename: &str, range: (Bound<u64>, Bound<u64>) - ) -> Result<Pin<Box<dyn Stream<Item = std::io::Result<Bytes>> + Send>>> { + ) -> impl Future<Output = Result<Pin<Box<dyn Stream<Item = std::io::Result<Bytes>> + Send>>>> + Send { async move { use futures::stream::TryStreamExt; use tracing::debug; let (metadata, mut stream) = self.read_streaming(domain, filename).await?; @@ -163,17 +165,17 @@ pub trait MediaStore: 'static + Send + Sync + Clone { ); return Ok(stream); - } + } } /// Read metadata for a file. /// /// The default implementation uses the `read_streaming` method /// and drops the stream containing file content. - async fn metadata(&self, domain: &str, filename: &str) -> Result<Metadata> { + fn metadata(&self, domain: &str, filename: &str) -> impl Future<Output = Result<Metadata>> + Send { async move { self.read_streaming(domain, filename) .await .map(|(meta, stream)| meta) - } + } } - async fn delete(&self, domain: &str, filename: &str) -> Result<()>; + fn delete(&self, domain: &str, filename: &str) -> impl Future<Output = Result<()>> + Send; } |