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
use crate::error::{InvalidDescription, InvalidReminderTime};
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use std::borrow::Borrow;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub struct Reminder {
time: DateTime<Utc>,
}
impl Reminder {
pub fn new(
reminder_time: DateTime<Utc>,
current_time: DateTime<Utc>,
) -> Result<Reminder, InvalidReminderTime> {
if reminder_time <= current_time {
Err(InvalidReminderTime)
} else {
Ok(Reminder {
time: reminder_time,
})
}
}
pub fn get_time(&self) -> DateTime<Utc> {
self.time
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct Description {
text: String,
}
impl Description {
pub fn new<S: Into<String>>(text: S) -> Result<Description, InvalidDescription> {
let text = text.into();
if text.is_empty() {
Err(InvalidDescription)
} else {
Ok(Description { text })
}
}
pub fn as_str(&self) -> &str {
self.text.borrow()
}
}
impl Borrow<str> for Description {
fn borrow(&self) -> &str {
self.text.borrow()
}
}