1use crate::Error;
6use crate::types::common::*;
7use crate::types::environment::EnvironmentRef;
8pub use cm_types::{AllowedOffers, Durability, Name};
9use json_spanned_value::Spanned;
10use reference_doc::ReferenceDoc;
11use serde::{Deserialize, Serialize};
12use std::path::PathBuf;
13use std::sync::Arc;
14
15#[derive(Deserialize, Debug, PartialEq, ReferenceDoc, Serialize)]
16#[serde(deny_unknown_fields)]
17#[reference_doc(fields_as = "list", top_level_doc_after_fields)]
18pub struct Collection {
29 pub name: Name,
33
34 pub durability: Durability,
40
41 pub environment: Option<EnvironmentRef>,
46
47 pub allowed_offers: Option<AllowedOffers>,
54
55 pub allow_long_names: Option<bool>,
58
59 pub persistent_storage: Option<bool>,
63}
64
65#[derive(Deserialize, Debug, PartialEq, Clone)]
66#[serde(deny_unknown_fields)]
67pub struct ParsedCollection {
68 pub name: Spanned<Name>,
69 pub durability: Spanned<Durability>,
70 pub environment: Option<Spanned<EnvironmentRef>>,
71 pub allowed_offers: Option<Spanned<AllowedOffers>>,
72 pub allow_long_names: Option<Spanned<bool>>,
73 pub persistent_storage: Option<Spanned<bool>>,
74}
75
76#[derive(Debug, Clone)]
77pub struct ContextCollection {
78 pub name: ContextSpanned<Name>,
79 pub durability: ContextSpanned<Durability>,
80 pub environment: Option<ContextSpanned<EnvironmentRef>>,
81 pub allowed_offers: Option<ContextSpanned<AllowedOffers>>,
82 pub allow_long_names: Option<ContextSpanned<bool>>,
83 pub persistent_storage: Option<ContextSpanned<bool>>,
84}
85
86impl PartialEq for ContextCollection {
87 fn eq(&self, other: &Self) -> bool {
88 macro_rules! cmp {
89 ($field:ident) => {
90 match (&self.$field, &other.$field) {
91 (Some(a), Some(b)) => a.value == b.value,
92 (None, None) => true,
93 _ => false,
94 }
95 };
96 }
97
98 self.name.value == other.name.value
99 && self.durability.value == other.durability.value
100 && cmp!(environment)
101 && cmp!(allowed_offers)
102 && cmp!(allow_long_names)
103 && cmp!(persistent_storage)
104 }
105}
106
107impl Eq for ContextCollection {}
108
109impl Hydrate for ParsedCollection {
110 type Output = ContextCollection;
111
112 fn hydrate(self, file: &Arc<PathBuf>, buffer: &String) -> Result<Self::Output, Error> {
113 Ok(ContextCollection {
114 name: hydrate_simple(self.name, file, buffer),
115 durability: hydrate_simple(self.durability, file, buffer),
116 environment: hydrate_opt_simple(self.environment, file, buffer),
117 allowed_offers: hydrate_opt_simple(self.allowed_offers, file, buffer),
118 allow_long_names: hydrate_opt_simple(self.allow_long_names, file, buffer),
119 persistent_storage: hydrate_opt_simple(self.persistent_storage, file, buffer),
120 })
121 }
122}