Helper methods

This commit is contained in:
Valentin Brandl 2019-08-07 18:50:52 +02:00
parent 566f4c0e01
commit b65df17a4e
No known key found for this signature in database
GPG Key ID: 30D341DD34118D7D

View File

@ -1,3 +1,11 @@
use crate::{
cache::{Cache, Key},
service::Service,
};
use std::sync::{Arc, RwLock};
pub(crate) type State = Arc<RwLock<Cache<Key, String>>>;
#[derive(Deserialize, Debug)] #[derive(Deserialize, Debug)]
pub(crate) struct FilePath { pub(crate) struct FilePath {
pub(crate) user: String, pub(crate) user: String,
@ -6,3 +14,17 @@ pub(crate) struct FilePath {
pub(crate) file: String, pub(crate) file: String,
} }
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(),
)
}
}