use super::{ManifestsTable, SnapshotsTable};
use crate::table::Table;
#[derive(Debug)]
pub struct MetadataTable<'a>(&'a Table);
#[derive(Debug, Clone, strum::EnumIter)]
pub enum MetadataTableType {
Snapshots,
Manifests,
}
impl MetadataTableType {
pub fn as_str(&self) -> &str {
match self {
MetadataTableType::Snapshots => "snapshots",
MetadataTableType::Manifests => "manifests",
}
}
pub fn all_types() -> impl Iterator<Item = Self> {
use strum::IntoEnumIterator;
Self::iter()
}
}
impl TryFrom<&str> for MetadataTableType {
type Error = String;
fn try_from(value: &str) -> std::result::Result<Self, String> {
match value {
"snapshots" => Ok(Self::Snapshots),
"manifests" => Ok(Self::Manifests),
_ => Err(format!("invalid metadata table type: {value}")),
}
}
}
impl<'a> MetadataTable<'a> {
pub fn new(table: &'a Table) -> Self {
Self(table)
}
pub fn snapshots(&self) -> SnapshotsTable<'_> {
SnapshotsTable::new(self.0)
}
pub fn manifests(&self) -> ManifestsTable<'_> {
ManifestsTable::new(self.0)
}
}