ligen_ir/library/metadata/
author.rs

1use std::fmt::Display;
2
3use crate::prelude::*;
4
5#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq)]
6pub struct Author {
7    pub name: String,
8    pub email: String,
9}
10
11impl Author {
12    pub fn new(name: impl Into<String>, email: impl Into<String>) -> Self {
13        let name = name.into();
14        let email = email.into();
15        Self { name, email }
16    }
17}
18
19impl Display for Author {
20    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
21        if self.email.is_empty() {
22            write!(f, "\"{}\"", self.name)
23        } else {
24            write!(f, "\"{} <{}>\"", self.name, self.email)
25        }
26    }
27}