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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
#![allow(rustdoc::private_intra_doc_links)]
#![deny(
    // Documentation
	// TODO: rustdoc::broken_intra_doc_links,
	// TODO: rustdoc::missing_crate_level_docs,
	// TODO: missing_docs,
	// TODO: clippy::missing_docs_in_private_items,
    //

    // Other
	deprecated_in_future,
	exported_private_dependencies,
	future_incompatible,
	missing_copy_implementations,
	missing_debug_implementations,
	private_in_public,
	rust_2018_compatibility,
	rust_2018_idioms,
	trivial_casts,
	trivial_numeric_casts,
	unsafe_code,
	unstable_features,
	unused_import_braces,
	unused_qualifications,

	// clippy attributes
	clippy::missing_const_for_fn,
	clippy::redundant_pub_crate,
	clippy::use_self
)]
#![cfg_attr(docsrs, feature(doc_cfg), feature(doc_alias))]

use serde::{Deserialize, Serialize};
#[cfg(feature = "validate")]
use serde_valid::Validate;

/// Resume Schema
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "validate", derive(Validate))]
#[serde(default)]
pub struct Resume {
	pub basics: Option<Basics>,
	pub work: Vec<Work>,
	pub volunteer: Vec<Volunteer>,
	pub education: Vec<Education>,
	/// Specify any awards you have received throughout your professional caree
	pub awards: Vec<Award>,
	/// Specify any certificates you have received throughout your professional career
	pub certificates: Vec<Certificate>,
	/// Specify your publications through your career
	pub publications: Vec<Publication>,
	/// List out your professional skill-set
	pub skills: Vec<Skill>,
	/// List any other languages you speak
	pub languages: Vec<Language>,
	pub interests: Vec<Interest>,
	/// List references you have received
	pub references: Vec<Reference>,
	/// Specify career projects
	pub projects: Vec<Project>,
	/// The schema version and any other tooling configuration lives here
	pub meta: Option<Meta>,
}

#[derive(Default, Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "validate", derive(Validate))]
#[serde(default)]
pub struct Basics {
	pub name: Option<String>,
	/// e.g. Web Developer
	pub label: Option<String>,
	/// URL (as per RFC 3986) to a image in JPEG or PNG format
	pub image: Option<String>,
	/// e.g. thomas@gmail.com
	pub email: Option<String>,
	/// Phone numbers are stored as strings so use any format you like, e.g. 712-117-2923
	pub phone: Option<String>,
	/// URL (as per RFC 3986) to your website, e.g. personal homepage
	pub url: Option<String>,
	/// Write a short 2-3 sentence biography about yourself
	pub summary: Option<String>,
	pub location: Location,
	/// Specify any number of social networks that you participate in
	pub profiles: Vec<Profile>,
}

#[derive(Default, Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "validate", derive(Validate))]
#[serde(default)]
pub struct Location {
	/// To add multiple address lines, use \n. For example, 1234 Glücklichkeit Straße\nHinterhaus 5. Etage li.
	pub address: Option<String>,
	#[serde(rename = "postalCode")]
	pub postal_code: Option<String>,
	pub city: Option<String>,
	/// code as per ISO-3166-1 ALPHA-2, e.g. US, AU, IN
	#[serde(rename = "countryCode")]
	pub country_code: Option<String>,
	/// The general region where you live. Can be a US state, or a province, for instance.
	pub region: Option<String>,
}

/// Specify any number of social networks that you participate in
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "validate", derive(Validate))]
#[serde(default)]
pub struct Profile {
	/// e.g. Facebook or Twitter
	pub network: Option<String>,
	/// e.g. neutralthoughts
	pub username: Option<String>,
	/// e.g. http://twitter.example.com/neutralthoughts
	pub url: Option<String>,
}

#[derive(Default, Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "validate", derive(Validate))]
#[serde(default)]
pub struct Work {
	/// e.g. Facebook
	pub name: Option<String>,
	/// e.g. Menlo Park, CA
	pub location: Option<String>,
	/// e.g. Social Media Company
	pub description: Option<String>,
	/// e.g. Software Engineer
	pub position: Option<String>,
	/// e.g. http://facebook.example.com
	pub url: Option<String>,
	#[serde(rename = "startDate")]
	#[cfg_attr(
		feature = "validate",
		validate(
			pattern = r"^([1-2][0-9]{3}-[0-1][0-9]-[0-3][0-9]|[1-2][0-9]{3}-[0-1][0-9]|[1-2][0-9]{3})$"
		)
	)]
	pub start_date: Option<String>,
	#[serde(rename = "endDate")]
	#[cfg_attr(
		feature = "validate",
		validate(
			pattern = r"^([1-2][0-9]{3}-[0-1][0-9]-[0-3][0-9]|[1-2][0-9]{3}-[0-1][0-9]|[1-2][0-9]{3})$"
		)
	)]
	pub end_date: Option<String>,
	/// Specify multiple accomplishments
	pub highlights: Vec<Highlight>,
}

/// e.g. Increased profits by 20% from 2011-2012 through viral advertising
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "validate", derive(Validate))]
pub struct Highlight(String);

#[derive(Default, Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "validate", derive(Validate))]
#[serde(default)]
pub struct Volunteer {
	/// e.g. Facebook
	pub organization: Option<String>,
	/// e.g. Software Engineer
	pub position: Option<String>,
	/// e.g. http://facebook.example.com
	pub url: Option<String>,
	#[serde(rename = "startDate")]
	#[cfg_attr(
		feature = "validate",
		validate(
			pattern = r"^([1-2][0-9]{3}-[0-1][0-9]-[0-3][0-9]|[1-2][0-9]{3}-[0-1][0-9]|[1-2][0-9]{3})$"
		)
	)]
	pub start_date: Option<String>,
	#[serde(rename = "endDate")]
	#[cfg_attr(
		feature = "validate",
		validate(
			pattern = r"^([1-2][0-9]{3}-[0-1][0-9]-[0-3][0-9]|[1-2][0-9]{3}-[0-1][0-9]|[1-2][0-9]{3})$"
		)
	)]
	pub end_date: Option<String>,
	/// Give an overview of your responsibilities at the company
	pub summary: Option<String>,
	/// Specify multiple accomplishments
	pub highlights: Vec<Highlight>,
}

#[derive(Default, Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "validate", derive(Validate))]
#[serde(default)]
pub struct Education {
	/// e.g. Massachusetts Institute of Technology
	pub institution: Option<String>,
	/// e.g. http://facebook.example.com
	pub url: Option<String>,
	/// e.g. Arts
	pub arae: Option<String>,
	/// e.g. Bachelor
	pub study_type: Option<String>,
	#[serde(rename = "startDate")]
	#[cfg_attr(
		feature = "validate",
		validate(
			pattern = r"^([1-2][0-9]{3}-[0-1][0-9]-[0-3][0-9]|[1-2][0-9]{3}-[0-1][0-9]|[1-2][0-9]{3})$"
		)
	)]
	pub start_date: Option<String>,
	#[serde(rename = "endDate")]
	#[cfg_attr(
		feature = "validate",
		validate(
			pattern = r"^([1-2][0-9]{3}-[0-1][0-9]-[0-3][0-9]|[1-2][0-9]{3}-[0-1][0-9]|[1-2][0-9]{3})$"
		)
	)]
	pub end_date: Option<String>,
	/// grade point average, e.g. 3.67/4.0
	pub score: Option<String>,
	/// List notable courses/subjects
	#[serde(default)]
	pub courses: Vec<Course>,
}

/// e.g. H1302 - Introduction to American history
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "validate", derive(Validate))]
pub struct Course(String);

/// Specify any awards you have received throughout your professional caree
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "validate", derive(Validate))]
#[serde(default)]
pub struct Award {
	/// e.g. One of the 100 greatest minds of the century
	pub title: Option<String>,
	#[cfg_attr(
		feature = "validate",
		validate(
			pattern = r"^([1-2][0-9]{3}-[0-1][0-9]-[0-3][0-9]|[1-2][0-9]{3}-[0-1][0-9]|[1-2][0-9]{3})$"
		)
	)]
	pub date: Option<String>,
	/// e.g. Time Magazine
	pub awarder: Option<String>,
	/// e.g. Received for my work with Quantum Physics
	pub summary: Option<String>,
}

/// Specify any certificates you have received throughout your professional career
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "validate", derive(Validate))]
#[serde(default)]
pub struct Certificate {
	/// e.g. Certified Kubernetes Administrator
	pub name: Option<String>,
	/// e.g. 1989-06-12
	pub date: Option<String>,
	/// e.g. http://example.com
	pub url: Option<String>,
	/// e.g. CNCF
	pub issuer: Option<String>,
}

/// Specify your publications through your career
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "validate", derive(Validate))]
#[serde(default)]
pub struct Publication {
	/// e.g. The World Wide Web
	pub name: Option<String>,
	/// e.g. IEEE, Computer Magazine
	pub publisher: Option<String>,
	#[serde(rename = "releaseDate")]
	#[cfg_attr(
		feature = "validate",
		validate(
			pattern = r"^([1-2][0-9]{3}-[0-1][0-9]-[0-3][0-9]|[1-2][0-9]{3}-[0-1][0-9]|[1-2][0-9]{3})$"
		)
	)]
	pub release_date: Option<String>,
	/// e.g. http://www.computer.org.example.com/csdl/mags/co/1996/10/rx069-abs.html
	pub url: Option<String>,
	/// Short summary of publication. e.g. Discussion of the World Wide Web, HTTP, HTML.
	pub summary: Option<String>,
}

/// List out your professional skill-set
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "validate", derive(Validate))]
#[serde(default)]
pub struct Skill {
	/// e.g. Web Development
	pub name: Option<String>,
	/// e.g. Master
	pub level: Option<String>,
	/// List some keywords pertaining to this skill
	pub keywords: Vec<Keyword>,
}

/// e.g. HTML
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "validate", derive(Validate))]
pub struct Keyword(String);

/// List any other languages you speak
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "validate", derive(Validate))]
#[serde(default)]
pub struct Language {
	/// e.g. English, Spanish
	pub language: Option<String>,
	/// e.g. Fluent, Beginner
	pub fluency: Option<String>,
}

#[derive(Default, Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "validate", derive(Validate))]
#[serde(default)]
pub struct Interest {
	/// e.g. Philosophy
	pub name: Option<String>,
	pub keywords: Vec<Keyword>,
}

/// List references you have received
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "validate", derive(Validate))]
#[serde(default)]
pub struct Reference {
	/// e.g. Timothy Cook
	pub name: Option<String>,
	/// e.g. Joe blogs was a great employee, who turned up to work at least once a week. He exceeded my expectations when it came to doing nothing.
	pub reference: Option<String>,
}

/// Specify career projects
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "validate", derive(Validate))]
#[serde(default)]
pub struct Project {
	/// e.g. The World Wide Web
	pub name: Option<String>,
	/// Short summary of project. e.g. Collated works of 2017.
	pub description: Option<String>,
	/// Specify multiple features
	pub highlights: Vec<Highlight>,
	/// Specify special elements involved
	pub keywords: Vec<Keyword>,
	#[serde(rename = "startDate")]
	#[cfg_attr(
		feature = "validate",
		validate(
			pattern = r"^([1-2][0-9]{3}-[0-1][0-9]-[0-3][0-9]|[1-2][0-9]{3}-[0-1][0-9]|[1-2][0-9]{3})$"
		)
	)]
	pub start_date: Option<String>,
	#[serde(rename = "endDate")]
	#[cfg_attr(
		feature = "validate",
		validate(
			pattern = r"^([1-2][0-9]{3}-[0-1][0-9]-[0-3][0-9]|[1-2][0-9]{3}-[0-1][0-9]|[1-2][0-9]{3})$"
		)
	)]
	pub end_date: Option<String>,
	/// e.g. http://www.computer.org/csdl/mags/co/1996/10/rx069-abs.html
	pub url: Option<String>,
	/// Specify your role on this project or in company
	pub roles: Vec<Role>,
	/// Specify the relevant company/entity affiliations e.g. 'greenpeace', 'corporationXYZ'
	pub entity: Option<String>,
	/// e.g. 'volunteering', 'presentation', 'talk', 'application', 'conference'
	pub r#type: Option<String>,
}

/// e.g. Team Lead, Speaker, Writer
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "validate", derive(Validate))]
pub struct Role(String);

/// The schema version and any other tooling configuration lives here
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "validate", derive(Validate))]
#[serde(default)]
pub struct Meta {
	/// URL (as per RFC 3986) to latest version of this document
	pub canonical: Option<String>,
	/// A version field which follows semver - e.g. v1.0.0
	pub version: Option<String>,
	/// Using ISO 8601 with YYYY-MM-DDThh:mm:ss
	#[serde(rename = "lastModified")]
	pub last_modified: Option<String>,
}

#[cfg(feature = "validate")]
#[cfg(test)]
mod validate {
	use super::*;

	#[test]
	fn sample() -> Result<(), Box<dyn std::error::Error>> {
		const SAMPLE: &str = include_str!("../sample.resume.json");

		let resume: Resume = serde_json::from_str(SAMPLE)?;
		resume.validate()?;

		Ok(())
	}

	#[test]
	#[ignore = "Run explicitly"]
	fn stdin() -> Result<(), Box<dyn std::error::Error>> {
		let resume_file = std::env::var_os("RESUME_FILE").unwrap();
		let resume = std::fs::read_to_string(resume_file)?;

		let resume: Resume = serde_json::from_str(&resume)?;
		resume.validate()?;

		println!("{resume:#?}");

		Ok(())
	}
}