unityrs_core/files/
changed.rs1use super::{BundleFile, File, Parent, ParentKind, WebFile};
5use std::sync::atomic::Ordering;
6
7impl Parent {
8 pub(crate) fn mark_changed(&self) {
9 match &self.kind {
10 ParentKind::Bundle { bundle, .. } => {
11 if let Some(file) = bundle.upgrade() {
12 file.mark_changed();
13 }
14 }
15 ParentKind::Web { web } => {
16 if let Some(file) = web.upgrade() {
17 file.mark_changed();
18 }
19 }
20 }
21 }
22}
23
24macro_rules! changed {
25 ($ty:ty) => {
26 impl $ty {
27 pub fn mark_changed(&self) {
29 if let Some(parent) = self.parent() {
30 parent.mark_changed();
31 }
32 self.changed.store(true, Ordering::Release);
33 }
34 #[must_use]
36 pub fn is_changed(&self) -> bool {
37 self.changed.load(Ordering::Acquire)
38 }
39 }
40 };
41}
42changed!(BundleFile);
43changed!(WebFile);
44
45impl File {
46 pub fn mark_changed(&self) {
48 match self {
49 Self::Serialized(f) => f.mark_changed(),
50 Self::Bundle(f) => f.mark_changed(),
51 Self::Web(f) => f.mark_changed(),
52 Self::Raw(_) => {}
53 }
54 }
55 #[must_use]
57 pub fn is_changed(&self) -> bool {
58 match self {
59 Self::Serialized(f) => f.is_changed(),
60 Self::Bundle(f) => f.is_changed(),
61 Self::Web(f) => f.is_changed(),
62 Self::Raw(_) => false,
63 }
64 }
65}