joat_repo/link.rs
1// Copyright (c) 2023 Richard Cook
2//
3// Permission is hereby granted, free of charge, to any person obtaining
4// a copy of this software and associated documentation files (the
5// "Software"), to deal in the Software without restriction, including
6// without limitation the rights to use, copy, modify, merge, publish,
7// distribute, sublicense, and/or sell copies of the Software, and to
8// permit persons to whom the Software is furnished to do so, subject to
9// the following conditions:
10//
11// The above copyright notice and this permission notice shall be
12// included in all copies or substantial portions of the Software.
13//
14// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21//
22use crate::link_id::LinkId;
23use crate::meta_id::MetaId;
24use chrono::{DateTime, Utc};
25use serde::{Deserialize, Serialize};
26use std::path::{Path, PathBuf};
27
28#[derive(Debug, Deserialize, Serialize)]
29pub struct LinkRecord {
30 pub(crate) created_at: DateTime<Utc>,
31 pub(crate) link_id: LinkId,
32 pub(crate) project_dir: PathBuf,
33 pub(crate) meta_id: MetaId,
34}
35
36#[derive(Debug)]
37pub struct Link {
38 link_path: PathBuf,
39 record: LinkRecord,
40}
41
42impl Link {
43 pub(crate) const fn new(link_path: PathBuf, record: LinkRecord) -> Self {
44 Self { link_path, record }
45 }
46
47 #[must_use]
48 pub fn link_path(&self) -> &Path {
49 &self.link_path
50 }
51
52 #[must_use]
53 pub const fn created_at(&self) -> &DateTime<Utc> {
54 &self.record.created_at
55 }
56
57 #[must_use]
58 pub const fn link_id(&self) -> &LinkId {
59 &self.record.link_id
60 }
61
62 #[must_use]
63 pub fn project_dir(&self) -> &Path {
64 &self.record.project_dir
65 }
66
67 #[must_use]
68 pub const fn meta_id(&self) -> &MetaId {
69 &self.record.meta_id
70 }
71}