Trait AnniProvider
此处描述 Rust
实现的 anni-provider
的基本 Trait
。其他语言可模仿设计类似接口。
#![allow(unused)]
fn main() {
/// AnniProvider is a common trait for anni resource providers.
/// It provides functions to get cover, audio, album list and reload.
#[async_trait]
pub trait AnniProvider {
/// Get album information provided by provider.
async fn albums(&self) -> Result<HashSet<Cow<str>>, ProviderError>;
/// Get audio info describing basic information of the audio file.
async fn get_audio_info(&self, album_id: &str, disc_id: u8, track_id: u8) -> Result<AudioInfo, ProviderError>;
/// Returns a reader implements AsyncRead for content reading
async fn get_audio(&self, album_id: &str, disc_id: u8, track_id: u8, range: Range) -> Result<AudioResourceReader, ProviderError>;
/// Returns a cover of corresponding album
async fn get_cover(&self, album_id: &str, disc_id: Option<u8>) -> Result<ResourceReader, ProviderError>;
/// Reloads the provider for new albums
async fn reload(&mut self) -> Result<(), ProviderError>;
}
}
其中获取返回的类型由 ResourceReader
和 AudioResourceReader
描述:
#![allow(unused)]
fn main() {
pub type ResourceReader = Pin<Box<dyn AsyncRead + Send>>;
pub struct AudioInfo {
/// File extension of the file
pub extension: String,
/// File size of the file
pub size: usize,
/// Audio duration of the file
pub duration: u64,
}
/// AudioResourceReader abstracts the file result a provider returns with extra information of audio
pub struct AudioResourceReader {
/// Audio info
pub info: AudioInfo,
/// File range
pub range: Range,
/// Async Reader for the file
pub reader: ResourceReader,
}
}