Skip to main content

braze_sync/resource/
mod.rs

1//! Domain types for the five resources braze-sync manages.
2//!
3//! See IMPLEMENTATION.md §6 for the complete type contracts. Adding a new
4//! variant to [`Resource`] / [`ResourceKind`] forces every `match` site in
5//! `diff/`, `fs/`, and `braze/` to be updated — that compiler-enforced
6//! exhaustiveness is the central reason braze-sync is written in Rust
7//! (§2.4).
8
9pub mod catalog;
10pub mod content_block;
11pub mod custom_attribute;
12pub mod email_template;
13
14pub use catalog::{Catalog, CatalogField, CatalogFieldType, CatalogItemRow, CatalogItems};
15pub use content_block::{ContentBlock, ContentBlockState};
16pub use custom_attribute::{CustomAttribute, CustomAttributeRegistry, CustomAttributeType};
17pub use email_template::EmailTemplate;
18
19/// Every resource type braze-sync manages, as a single sum type.
20///
21/// Adding a variant here will produce match-exhaustiveness errors at every
22/// downstream site that consumes a `Resource`. That is intentional.
23#[derive(Debug, Clone, PartialEq)]
24pub enum Resource {
25    CatalogSchema(Catalog),
26    CatalogItems(CatalogItems),
27    ContentBlock(ContentBlock),
28    EmailTemplate(EmailTemplate),
29    CustomAttributeRegistry(CustomAttributeRegistry),
30}
31
32/// Lightweight tag for filtering / CLI args. Mirrors [`Resource`] but
33/// without the payload.
34#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, clap::ValueEnum)]
35#[clap(rename_all = "snake_case")]
36pub enum ResourceKind {
37    CatalogSchema,
38    CatalogItems,
39    ContentBlock,
40    EmailTemplate,
41    CustomAttribute,
42}
43
44impl ResourceKind {
45    pub fn as_str(&self) -> &'static str {
46        match self {
47            Self::CatalogSchema => "catalog_schema",
48            Self::CatalogItems => "catalog_items",
49            Self::ContentBlock => "content_block",
50            Self::EmailTemplate => "email_template",
51            Self::CustomAttribute => "custom_attribute",
52        }
53    }
54
55    pub fn all() -> &'static [Self] {
56        &[
57            Self::CatalogSchema,
58            Self::CatalogItems,
59            Self::ContentBlock,
60            Self::EmailTemplate,
61            Self::CustomAttribute,
62        ]
63    }
64}
65
66impl Resource {
67    pub fn kind(&self) -> ResourceKind {
68        match self {
69            Self::CatalogSchema(_) => ResourceKind::CatalogSchema,
70            Self::CatalogItems(_) => ResourceKind::CatalogItems,
71            Self::ContentBlock(_) => ResourceKind::ContentBlock,
72            Self::EmailTemplate(_) => ResourceKind::EmailTemplate,
73            Self::CustomAttributeRegistry(_) => ResourceKind::CustomAttribute,
74        }
75    }
76}