#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(transparent))]
pub struct InstanceId(pub String);
impl InstanceId {
pub fn local() -> Self {
Self("local".to_string())
}
}
impl Default for InstanceId {
fn default() -> Self {
Self::local()
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(transparent))]
pub struct AuthorityScope(pub String);
impl AuthorityScope {
pub fn local() -> Self {
Self(InstanceId::local().0)
}
}
impl Default for AuthorityScope {
fn default() -> Self {
Self::local()
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn local_instance_id_is_the_constant_local() {
assert_eq!(InstanceId::local().0, "local");
assert_eq!(InstanceId::default().0, "local");
}
#[test]
fn local_authority_scope_mirrors_local_instance() {
assert_eq!(AuthorityScope::local().0, "local");
assert_eq!(AuthorityScope::default().0, InstanceId::local().0);
}
#[test]
fn instance_id_is_type_distinct_from_authority_scope() {
let _: InstanceId = InstanceId("prod-hub".into());
let _: AuthorityScope = AuthorityScope("prod-hub/ijima".into());
assert_ne!(InstanceId("x".into()), InstanceId("y".into()));
}
}