#![doc = include_str!("../README.md")]

use std::fmt;

use serde::{Deserialize, Serialize};

mod error;
mod index;
mod input;
mod output;

pub use output::Output;


#[derive(Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[serde(transparent)]
pub(crate) struct CacheId {
    pub value: String,
}
impl fmt::Debug for CacheId {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        self.value.fmt(f)
    }
}
impl fmt::Display for CacheId {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        self.value.fmt(f)
    }
}

#[derive(Clone, Debug, PartialEq, Eq)]
pub(crate) enum ChangeIndicator {
    Exists(String),
    ExistsNot,
}

impl ChangeIndicator {
    fn has_changed_from(&self, previous: &ChangeIndicator) -> bool {
        if matches!(previous, &ChangeIndicator::ExistsNot) { //always consider changed when uncached
            return true;
        }

        previous != self
    }
}
