scitadel_core/models/
mod.rs1mod assessment;
2mod citation;
3mod doi;
4mod paper;
5mod question;
6mod search;
7
8pub use assessment::Assessment;
9pub use citation::{Citation, CitationDirection, SnowballRun};
10pub use doi::{doi_to_filename, normalize_doi, validate_doi};
11pub use paper::{CandidatePaper, Paper};
12pub use question::{ResearchQuestion, SearchTerm};
13pub use search::{Search, SearchResult, SourceOutcome, SourceStatus};
14
15use serde::{Deserialize, Serialize};
16use uuid::Uuid;
17
18macro_rules! newtype_id {
20 ($name:ident) => {
21 #[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
22 #[serde(transparent)]
23 pub struct $name(pub String);
24
25 impl $name {
26 #[must_use]
27 pub fn new() -> Self {
28 Self(Uuid::new_v4().simple().to_string())
29 }
30
31 #[must_use]
32 pub fn as_str(&self) -> &str {
33 &self.0
34 }
35
36 #[must_use]
37 pub fn short(&self) -> &str {
38 &self.0[..self.0.len().min(8)]
39 }
40
41 #[must_use]
42 pub fn starts_with(&self, prefix: &str) -> bool {
43 self.0.starts_with(prefix)
44 }
45 }
46
47 impl Default for $name {
48 fn default() -> Self {
49 Self::new()
50 }
51 }
52
53 impl std::fmt::Display for $name {
54 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
55 write!(f, "{}", self.0)
56 }
57 }
58
59 impl From<String> for $name {
60 fn from(s: String) -> Self {
61 Self(s)
62 }
63 }
64
65 impl From<&str> for $name {
66 fn from(s: &str) -> Self {
67 Self(s.to_string())
68 }
69 }
70
71 impl AsRef<str> for $name {
72 fn as_ref(&self) -> &str {
73 &self.0
74 }
75 }
76 };
77}
78
79newtype_id!(PaperId);
80newtype_id!(SearchId);
81newtype_id!(QuestionId);
82newtype_id!(AssessmentId);
83newtype_id!(SearchTermId);
84newtype_id!(SnowballRunId);