我有一个HashMap<String, serde_json::Value>
,我想将其转换为HashMap<String, Attribute>
。我想根据名称(带有值)将字段转换为Attribute
:
pub struct Name {
pub first_name: String,
pub last_name: String,
}
pub enum Attribute {
__Noop,
Name(Name),
Age(i32),
Id(String),
}
impl Attribute {
fn new<T>(field_name: &str, attrs: T) -> Attribute {
if field_name == "name" {
Attribute::Name(attrs)
} else if field_name == "age" {
Attribute::Age(attrs)
} else if field_name == "id" {
Attribute::Id(attrs)
} else {
Attribute::__Noop
}
}
}
fn main() {}