yagcdn/backend/src/data.rs

31 lines
710 B
Rust
Raw Normal View History

2019-08-07 18:50:52 +02:00
use crate::{
cache::{Cache, Key},
service::Service,
};
use std::sync::{Arc, RwLock};
pub(crate) type State = Arc<RwLock<Cache<Key, String>>>;
2019-07-24 17:54:00 +02:00
#[derive(Deserialize, Debug)]
pub(crate) struct FilePath {
2019-08-07 20:41:01 +02:00
pub(crate) user: Arc<String>,
pub(crate) repo: Arc<String>,
pub(crate) commit: Arc<String>,
pub(crate) file: Arc<String>,
2019-07-24 17:54:00 +02:00
}
2019-08-07 18:50:52 +02:00
impl FilePath {
pub(crate) fn path(&self) -> String {
format!("{}/{}/{}/{}", self.user, self.repo, self.commit, self.file)
}
pub(crate) fn to_key<T: Service>(&self) -> Key {
Key::new(
T::cache_service(),
self.user.clone(),
self.repo.clone(),
self.commit.clone(),
)
}
}