fontpm_api/
source.rs

1use std::collections::HashMap;
2use std::path::PathBuf;
3use crate::host::FpmHost;
4use async_trait::async_trait;
5use crate::error::Error;
6use crate::font::{DefinedFontInstallSpec, DefinedFontVariantSpec, FontDescription, FontInstallSpec};
7
8#[derive(PartialEq, Eq)]
9pub enum RefreshOutput {
10    AlreadyUpToDate,
11    Downloaded
12}
13
14#[async_trait]
15pub trait Source<'host>: Send + Sync {
16    fn id(&self) -> &'host str;
17    fn name(&self) -> &'host str;
18
19    fn set_host(&mut self, host: &'host dyn FpmHost);
20
21    async fn refresh(&self, force_refresh: bool) -> Result<RefreshOutput, Error>;
22    async fn resolve_font(&self, spec: &FontInstallSpec) -> Result<(DefinedFontInstallSpec, FontDescription), Error>;
23    async fn download_font(&self, spec: &DefinedFontInstallSpec, dir: &PathBuf) -> Result<HashMap<DefinedFontVariantSpec, PathBuf>, Error>;
24    fn description(&self) -> SourceDescription {
25        SourceDescription {
26            id: self.id().to_string(),
27            name: self.id().to_string()
28        }
29    }
30}
31
32#[derive(Clone, Debug)]
33pub struct SourceDescription {
34    pub id: String,
35    pub name: String
36}
37pub trait SourceExt {
38    fn description(&self) -> SourceDescription;
39}