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