1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
use chrono::NaiveDateTime;
use crate::validation::{self, *};
pub struct BCard {
pub name: Option<Name>,
pub nickname: Option<String>,
pub label: Option<TypedProperty<String>>,
pub address: Option<TypedProperty<Address>>,
pub emails: Option<Vec<TypedProperty<String>>>,
pub title: Option<String>,
pub role: Option<String>,
pub organization: Option<String>,
pub urls: Option<Vec<TypedProperty<String>>>,
pub telephones: Option<Vec<TypedProperty<String>>>,
pub revision: Option<NaiveDateTime>,
}
impl BCard {
pub fn new() -> Self {
Self {
name: None,
nickname: None,
label: None,
address: None,
emails: None,
title: None,
role: None,
organization: None,
urls: None,
telephones: None,
revision: None,
}
}
}
impl Validation for BCard {
fn validate(&self) -> Result<(), ValidationError> {
let mut result = Ok(());
result = match &self.name {
Some(n) => validation::add_results(result, n.validate()),
None => Err( ValidationError{ messages: vec![String::from("Name cannot be empty")] } ),
};
// TODO add some more validation
result
}
}
pub struct Name {
pub prefix: Option<String>,
pub first_name: Option<String>,
pub middle_name: Option<String>,
pub family_name: Option<String>,
pub suffix: Option<String>,
}
impl Name {
pub fn new() -> Self {
Self {
prefix: None,
first_name: None,
middle_name: None,
family_name: None,
suffix: None,
}
}
}
impl Validation for Name {
fn validate(&self) -> std::result::Result<(), ValidationError> { todo!() }
}
pub enum WorkHomeType {
Home,
Work,
}
pub struct TypedProperty<T> {
pub p_type: Option<WorkHomeType>,
pub value: T,
}
pub struct Address {
pub street: Option<String>,
pub city: Option<String>,
pub locality: Option<String>,
pub postal_code: Option<String>,
pub country: Option<String>,
}
|