message: Use macro-based enum for extensibility
diff: @@ -17,16 +17,17 @@ const MAX_CONCURRENT_UPLOADS: usize = 1000;
  pub type CompressionAlgorithms = HashSet<CompressionAlgorithm>;
  -// NOTE: the `TryFrom` impl must be updated whenever a new variant is added.
  +macro_rules! enum_id {
  + ($vis:vis enum $name:ident { $($variant:ident = $discriminant:expr,)* }) => {
  #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
  -pub enum CompressionAlgorithm {
  - Zstd = 0,
  + $vis enum $name {
  + $($variant = $discriminant,)*
  }
  impl fmt::Display for CompressionAlgorithm {
  fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
  match self {
  - CompressionAlgorithm::Zstd => write!(f, "zstd"),
  + $(Self::$variant => write!(f, stringify!($variant)),)*
  }
  }
  }
  @@ -35,7 +36,7 @@ impl std::str::FromStr for CompressionAlgorithm {
  type Err = ();
  fn from_str(s: &str) -> Result<Self, Self::Err> {
  match s {
  - "zstd" => Ok(CompressionAlgorithm::Zstd),
  + $(stringify!($variant) => Ok(Self::$variant),)*
  _ => Err(()),
  }
  }
  @@ -45,11 +46,19 @@ impl std::convert::TryFrom<i32> for CompressionAlgorithm {
  type Error = i32;
  fn try_from(i: i32) -> Result<Self, Self::Error> {
  match i {
  - 0 => Ok(Self::Zstd),
  + $($discriminant => Ok(Self::$variant),)*
  _ => Err(i),
  }
  }
  }
  + }
  +}
  +
  +enum_id! {
  + pub enum CompressionAlgorithm {
  + Zstd = 0,
  + }
  +}
  #[derive(Clone, Debug, PartialEq, Eq, Hash)]
  pub(crate) struct Blob {
  