use std::collections::HashMap;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct SignerAttributes {
pub region: Option<String>,
pub expertise: Vec<String>,
pub nationality: Option<String>,
pub role: Vec<String>,
pub custom: HashMap<String, String>,
}
impl SignerAttributes {
pub fn new() -> Self {
Self::default()
}
pub fn with_region(mut self, region: impl Into<String>) -> Self {
self.region = Some(region.into());
self
}
pub fn with_expertise(mut self, expertise: impl Into<String>) -> Self {
self.expertise.push(expertise.into());
self
}
pub fn with_role(mut self, role: impl Into<String>) -> Self {
self.role.push(role.into());
self
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn build_attributes() {
let attrs = SignerAttributes::new()
.with_region("europe")
.with_expertise("metrology")
.with_role("director");
assert_eq!(attrs.region.as_deref(), Some("europe"));
assert_eq!(attrs.expertise, vec!["metrology"]);
assert_eq!(attrs.role, vec!["director"]);
}
}