Skip to main content

FileBackend

Trait FileBackend 

Source
pub trait FileBackend:
    Send
    + Sync
    + Debug {
    // Required methods
    fn get_by_hash(
        &self,
        hash: &str,
    ) -> impl Future<Output = Result<Option<(CachedFile, PathBuf)>>> + Send;
    fn get_by_video_and_format(
        &self,
        video_id: &str,
        format_id: &str,
    ) -> impl Future<Output = Result<Option<(CachedFile, PathBuf)>>> + Send;
    fn get_by_video_and_preferences(
        &self,
        video_id: &str,
        preferences: &FormatPreferences,
    ) -> impl Future<Output = Result<Option<(CachedFile, PathBuf)>>> + Send;
    fn put(
        &self,
        file: CachedFile,
        source_path: &Path,
    ) -> impl Future<Output = Result<PathBuf>> + Send;
    fn remove(&self, id: &str) -> impl Future<Output = Result<()>> + Send;
    fn clean(&self) -> impl Future<Output = Result<()>> + Send;
    fn get_thumbnail_by_video_id(
        &self,
        video_id: &str,
    ) -> impl Future<Output = Result<Option<(CachedThumbnail, PathBuf)>>> + Send;
    fn put_thumbnail(
        &self,
        thumbnail: CachedThumbnail,
        source_path: &Path,
    ) -> impl Future<Output = Result<PathBuf>> + Send;
    fn get_subtitle_by_language(
        &self,
        video_id: &str,
        language: &str,
    ) -> impl Future<Output = Result<Option<(CachedFile, PathBuf)>>> + Send;
}
Expand description

Trait for file cache backend implementations.

Required Methods§

Source

fn get_by_hash( &self, hash: &str, ) -> impl Future<Output = Result<Option<(CachedFile, PathBuf)>>> + Send

Retrieves a file from the cache by its hash.

§Arguments
  • hash - The content hash of the file
§Returns

The cached file entry and its path, or None if not found.

§Errors

Returns an error if the underlying I/O or deserialization fails.

Source

fn get_by_video_and_format( &self, video_id: &str, format_id: &str, ) -> impl Future<Output = Result<Option<(CachedFile, PathBuf)>>> + Send

Retrieves a file from the cache by video ID and format ID.

§Arguments
  • video_id - The video identifier
  • format_id - The format identifier
§Returns

The cached file entry and its path, or None if not found.

§Errors

Returns an error if the underlying I/O or deserialization fails.

Source

fn get_by_video_and_preferences( &self, video_id: &str, preferences: &FormatPreferences, ) -> impl Future<Output = Result<Option<(CachedFile, PathBuf)>>> + Send

Retrieves a file from the cache based on video ID and quality preferences.

§Arguments
  • video_id - The video identifier
  • preferences - The format preferences to match against
§Returns

The cached file entry and its path, or None if no match.

§Errors

Returns an error if the underlying I/O or deserialization fails.

Source

fn put( &self, file: CachedFile, source_path: &Path, ) -> impl Future<Output = Result<PathBuf>> + Send

Store a file in the cache.

§Arguments
  • file - The cached file metadata
  • source_path - Path to the source file to store
§Errors

Returns an error if the file cannot be stored.

§Returns

The path where the file was cached.

Source

fn remove(&self, id: &str) -> impl Future<Output = Result<()>> + Send

Removes a file from the cache by its ID.

§Arguments
  • id - The unique identifier of the cached file
§Errors

Returns an error if the removal operation fails.

Source

fn clean(&self) -> impl Future<Output = Result<()>> + Send

Cleans expired entries from the cache.

§Errors

Returns an error if the cleanup operation fails.

Source

fn get_thumbnail_by_video_id( &self, video_id: &str, ) -> impl Future<Output = Result<Option<(CachedThumbnail, PathBuf)>>> + Send

Retrieve a thumbnail from the cache by video ID.

§Arguments
  • video_id - The video identifier
§Returns

The cached thumbnail entry and its path, or None if not found.

§Errors

Returns an error if the underlying I/O or deserialization fails.

Source

fn put_thumbnail( &self, thumbnail: CachedThumbnail, source_path: &Path, ) -> impl Future<Output = Result<PathBuf>> + Send

Store a thumbnail in the cache.

§Arguments
  • thumbnail - The cached thumbnail metadata
  • source_path - Path to the source thumbnail file
§Errors

Returns an error if the thumbnail cannot be stored.

§Returns

The path where the thumbnail was cached.

Source

fn get_subtitle_by_language( &self, video_id: &str, language: &str, ) -> impl Future<Output = Result<Option<(CachedFile, PathBuf)>>> + Send

Retrieve a subtitle from the cache by video ID and language.

§Arguments
  • video_id - The video identifier
  • language - The subtitle language code
§Returns

The cached subtitle file entry and its path, or None if not found.

§Errors

Returns an error if the underlying I/O or deserialization fails.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§