From b65df17a4e41b67898b4a8fc0adbb8d72ff7eaa2 Mon Sep 17 00:00:00 2001 From: Valentin Brandl Date: Wed, 7 Aug 2019 18:50:52 +0200 Subject: [PATCH] Helper methods --- backend/src/data.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/backend/src/data.rs b/backend/src/data.rs index d68166e..5439e68 100644 --- a/backend/src/data.rs +++ b/backend/src/data.rs @@ -1,3 +1,11 @@ +use crate::{ + cache::{Cache, Key}, + service::Service, +}; +use std::sync::{Arc, RwLock}; + +pub(crate) type State = Arc>>; + #[derive(Deserialize, Debug)] pub(crate) struct FilePath { pub(crate) user: String, @@ -6,3 +14,17 @@ pub(crate) struct FilePath { 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(&self) -> Key { + Key::new( + T::cache_service(), + self.user.clone(), + self.repo.clone(), + self.commit.clone(), + ) + } +}