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
use crateAnnotation;
use env;
use OpenOptions;
use ;
use ;
/// Get the annotations metadata file path.
///
/// This function retrieves the home directory path of the current user and appends the
/// ".annotations" file name to it, forming the complete file path for storing annotations.
///
/// # Returns
///
/// A `String` containing the complete file path for the annotations metadata file, including the
/// home directory and the filename.
///
/// # Panics
///
/// This function may panic if it fails to retrieve the home directory path. In a typical
/// Unix-like environment, the "HOME" environment variable is expected to be set.
///
/// # Examples
///
/// ```
/// let filename = get_annotations_filename();
/// println!("Annotations file path: {}", filename);
/// ```
///
/// # Note
///
/// - This function is designed to provide a standardized file path for the annotations file,
/// assuming that it should be stored in the user's home directory with the filename ".annotations".
/// Appends a new annotation to the metadata file with a timestamp and content.
///
/// This function is used to add a new annotation to the metadata, including a timestamp indicating when
/// the annotation was created and the textual content of the annotation. The annotations are stored
/// in a specific format where each line represents an annotation entry.
///
/// # Arguments
///
/// - `content`: A `String` containing the textual content of the annotation to be added.
///
/// # Examples
///
/// ```
/// let content = "This is a new annotation.";
/// annotate(content.to_string());
/// ```
///
/// # Note
///
/// - This function is designed to add new annotations to the metadata file in a specific format, where each line
/// represents an annotation entry. The format is as follows:
///
/// ```
/// <TIMESTAMP> <CONTENT>
/// ```
///
/// where:
///
/// - `<TIMESTAMP>` is the timestamp in milliseconds indicating when the annotation was created.
/// - `<CONTENT>` is the textual content of the annotation.
///
/// - The `annotate` function appends the new annotation to the file, ensuring that it adheres to the
/// specified format.
///
/// - If the operation fails (e.g., due to file I/O issues), an error message is printed to the
/// standard error stream.
/// Reads and parses annotations from the metadata file into a vector of `Annotation` instances.
///
/// This function is responsible for reading and parsing annotations from a file and converting
/// them into a vector of `Annotation` instances. Annotations in the file should be stored in a
/// specific format, with each line representing an annotation entry containing a timestamp and
/// content.
///
/// # Returns
///
/// - A `Vec<Annotation>` containing parsed annotations.
///
/// # Panics
///
/// - If the annotations file cannot be read or if any annotation entry is in an invalid format,
/// the function will panic with an error message.
///
/// # Examples
///
/// ```
/// let annotations = read_annotations();
/// for annotation in &annotations {
/// println!("Timestamp: {}, Content: {}", annotation.created_at, annotation.content);
/// }
/// ```
///
/// # Note
///
/// - This function is designed to read and parse annotations from a file where each line follows
/// the specified format:
///
/// ```
/// <TIMESTAMP> <CONTENT>
/// ```
///
/// where:
///
/// - `<TIMESTAMP>` is the timestamp in milliseconds indicating when the annotation was created.
/// - `<CONTENT>` is the textual content of the annotation.
///
/// - If the annotations file is not found, empty, or contains entries in an invalid format, the function
/// will panic with an error message.
/// Reads and collects lines from an annotations file.
///
/// This function is responsible for opening and reading an annotations file, collecting its lines,
/// and returning them as a `Result<Vec<String>, io::Error>`. If the file is not found or cannot
/// be opened, the function will return an error.
///
/// # Returns
///
/// - A `Result` containing either a `Vec<String>` with lines from the file or an `io::Error` in case
/// of file I/O issues.
///
/// # Examples
///
/// ```
/// match read_annotations_file() {
/// Ok(lines) => {
/// for line in lines {
/// println!("{}", line);
/// }
/// }
/// Err(e) => {
/// eprintln!("Error reading annotations file: {}", e);
/// }
/// }
/// ```
///
/// # Note
///
/// - This function is designed to read and collect lines from an annotations file. It returns the lines
/// as a `Result<Vec<String>, io::Error>`.
///
/// - If the annotations file is not found, it will create an empty file and return an empty `Vec<String>`.