use super::{BundleFile, File, Parent, ParentKind, WebFile};
use std::sync::atomic::Ordering;
impl Parent {
pub(crate) fn mark_changed(&self) {
match &self.kind {
ParentKind::Bundle { bundle, .. } => {
if let Some(file) = bundle.upgrade() {
file.mark_changed();
}
}
ParentKind::Web { web } => {
if let Some(file) = web.upgrade() {
file.mark_changed();
}
}
}
}
}
macro_rules! changed {
($ty:ty) => {
impl $ty {
pub fn mark_changed(&self) {
if let Some(parent) = self.parent() {
parent.mark_changed();
}
self.changed.store(true, Ordering::Release);
}
#[must_use]
pub fn is_changed(&self) -> bool {
self.changed.load(Ordering::Acquire)
}
}
};
}
changed!(BundleFile);
changed!(WebFile);
impl File {
pub fn mark_changed(&self) {
match self {
Self::Serialized(f) => f.mark_changed(),
Self::Bundle(f) => f.mark_changed(),
Self::Web(f) => f.mark_changed(),
Self::Raw(_) => {}
}
}
#[must_use]
pub fn is_changed(&self) -> bool {
match self {
Self::Serialized(f) => f.is_changed(),
Self::Bundle(f) => f.is_changed(),
Self::Web(f) => f.is_changed(),
Self::Raw(_) => false,
}
}
}