this repo has no description
at main 2.0 kB view raw
1use async_trait::async_trait; 2use bytes::Bytes; 3use futures::Stream; 4use std::pin::Pin; 5use std::time::Duration; 6 7#[derive(Debug, thiserror::Error)] 8pub enum StorageError { 9 #[error("IO error: {0}")] 10 Io(#[from] std::io::Error), 11 #[error("S3 error: {0}")] 12 S3(String), 13 #[error("Other: {0}")] 14 Other(String), 15} 16 17pub struct StreamUploadResult { 18 pub sha256_hash: [u8; 32], 19 pub size: u64, 20} 21 22#[async_trait] 23pub trait BlobStorage: Send + Sync { 24 async fn put(&self, key: &str, data: &[u8]) -> Result<(), StorageError>; 25 async fn put_bytes(&self, key: &str, data: Bytes) -> Result<(), StorageError>; 26 async fn get(&self, key: &str) -> Result<Vec<u8>, StorageError>; 27 async fn get_bytes(&self, key: &str) -> Result<Bytes, StorageError>; 28 async fn get_head(&self, key: &str, size: usize) -> Result<Bytes, StorageError>; 29 async fn delete(&self, key: &str) -> Result<(), StorageError>; 30 async fn put_stream( 31 &self, 32 key: &str, 33 stream: Pin<Box<dyn Stream<Item = Result<Bytes, std::io::Error>> + Send>>, 34 ) -> Result<StreamUploadResult, StorageError>; 35 async fn copy(&self, src_key: &str, dst_key: &str) -> Result<(), StorageError>; 36} 37 38#[derive(Debug, thiserror::Error)] 39pub enum CacheError { 40 #[error("Cache connection error: {0}")] 41 Connection(String), 42 #[error("Serialization error: {0}")] 43 Serialization(String), 44} 45 46#[async_trait] 47pub trait Cache: Send + Sync { 48 async fn get(&self, key: &str) -> Option<String>; 49 async fn set(&self, key: &str, value: &str, ttl: Duration) -> Result<(), CacheError>; 50 async fn delete(&self, key: &str) -> Result<(), CacheError>; 51 async fn get_bytes(&self, key: &str) -> Option<Vec<u8>>; 52 async fn set_bytes(&self, key: &str, value: &[u8], ttl: Duration) -> Result<(), CacheError>; 53} 54 55#[async_trait] 56pub trait DistributedRateLimiter: Send + Sync { 57 async fn check_rate_limit(&self, key: &str, limit: u32, window_ms: u64) -> bool; 58}