use crate::annotations::impl_helpers::impl_namespace;
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use std::collections::HashMap;
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum VersionedTypeNamesAnnotations {
V1(TypeNamesAnnotationsV1),
}
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
pub struct TypeNamesAnnotationsV1 {
pub structs: HashMap<SierraTypeId, StructInfo>,
pub enums: HashMap<SierraTypeId, EnumInfo>,
}
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
pub struct StructInfo {
pub name: String,
pub members: Vec<String>,
}
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
pub struct EnumInfo {
pub name: String,
pub variants: Vec<String>,
}
#[derive(Clone, Debug, Eq, PartialEq, Hash, Serialize, Deserialize)]
pub struct SierraTypeId(pub u64);
impl Serialize for VersionedTypeNamesAnnotations {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
match self {
VersionedTypeNamesAnnotations::V1(v1) => v1.serialize(serializer),
}
}
}
impl<'de> Deserialize<'de> for VersionedTypeNamesAnnotations {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
TypeNamesAnnotationsV1::deserialize(deserializer).map(VersionedTypeNamesAnnotations::V1)
}
}
impl_namespace!(
"github.com/software-mansion-labs/cairo-debugger/user-types",
TypeNamesAnnotationsV1,
VersionedTypeNamesAnnotations
);