use serde::{Deserialize, Serialize};
use super::{Branch, Commit};
use std::path::PathBuf;
#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct ParsedResource {
pub commit: Commit, pub branch: Option<Branch>, pub file_path: PathBuf, pub resource: PathBuf, }
impl ParsedResource {
pub fn version(&self) -> String {
match &self.branch {
Some(branch) => branch.name.clone(),
None => self.commit.id.clone(),
}
}
}
impl std::fmt::Display for ParsedResource {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match &self.branch {
Some(branch) => write!(f, "{}/{}", branch.name, self.file_path.to_string_lossy()),
None => write!(f, "{}/{}", self.commit.id, self.file_path.to_string_lossy()),
}
}
}