1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
use std::borrow::Cow;

use serde::{Deserialize, Serialize};

/// Unique identifier for an `ItemId`, `Cow<'static, str>` newtype.
///
/// Must begin with a letter or underscore, and contain only letters, numbers,
/// and underscores.
///
/// # Examples
///
/// The following are all examples of valid `ItemId`s:
///
/// ```rust
/// # use peace_core::{item_id, ItemId};
/// #
/// let _snake = item_id!("snake_case");
/// let _camel = item_id!("camelCase");
/// let _pascal = item_id!("PascalCase");
/// ```
///
/// # Design Note
///
/// TODO: Experiment with upgrades.
///
/// For backward compatibility and migrating items from old IDs to new IDs, e.g.
/// when they were deployed with an old version of the automation software,
/// there needs to be a way to:
///
/// * Read state using the old ID.
/// * Either clean up that state, or migrate that state into an Item with the
///   new ID.
#[derive(Clone, Debug, Hash, PartialEq, Eq, Deserialize, Serialize)]
pub struct ItemId(Cow<'static, str>);

crate::id_newtype!(ItemId, ItemIdInvalidFmt, item_id, code_inline);