Skip to main content

mz_repr/
cluster_replica_size_id.rs

1// Copyright Materialize, Inc. and contributors. All rights reserved.
2//
3// Use of this software is governed by the Business Source License
4// included in the LICENSE file.
5//
6// As of the Change Date specified in that file, in accordance with
7// the Business Source License, use of this software will be governed
8// by the Apache License, Version 2.0.
9
10use std::fmt;
11
12#[cfg(any(test, feature = "proptest"))]
13use proptest_derive::Arbitrary;
14use serde::{Deserialize, Serialize};
15
16/// The identifier for a cluster replica size.
17///
18/// System sizes come from the `--cluster-replica-sizes` flag.
19#[derive(
20    Clone,
21    Copy,
22    Debug,
23    Eq,
24    PartialEq,
25    Ord,
26    PartialOrd,
27    Hash,
28    Serialize,
29    Deserialize
30)]
31#[cfg_attr(any(test, feature = "proptest"), derive(Arbitrary))]
32pub enum ClusterReplicaSizeId {
33    System(u64),
34    User(u64),
35}
36
37impl ClusterReplicaSizeId {
38    pub fn is_system(&self) -> bool {
39        matches!(self, Self::System(_))
40    }
41}
42
43impl fmt::Display for ClusterReplicaSizeId {
44    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
45        match self {
46            Self::System(id) => write!(f, "s{id}"),
47            Self::User(id) => write!(f, "u{id}"),
48        }
49    }
50}