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