1use std::{error::Error, fmt, sync::Arc};
7
8use surrealdb::{Connection, Surreal};
9
10use crate::parsers::{CsharpParseError, RustdocParseError};
11use crate::store::{StoreError, SurrealDocStore};
12
13pub mod data;
14pub mod ingest;
15pub mod metadata;
16
17pub use ingest::{CsharpIngestReport, CsharpIngestRequest};
18pub use ingest::{RustdocIngestReport, RustdocIngestRequest};
19pub use metadata::ProjectUpsertRequest;
20
21#[derive(Debug)]
23pub enum ControlError {
24 Parse(CsharpParseError),
26 RustdocParse(RustdocParseError),
28 Store(StoreError),
29}
30
31impl fmt::Display for ControlError {
32 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
33 match self {
34 Self::Parse(err) => write!(f, "{err}"),
35 Self::RustdocParse(err) => write!(f, "{err}"),
36 Self::Store(err) => write!(f, "{err}"),
37 }
38 }
39}
40
41impl Error for ControlError {}
42
43impl From<CsharpParseError> for ControlError {
44 fn from(err: CsharpParseError) -> Self {
45 Self::Parse(err)
46 }
47}
48
49impl From<RustdocParseError> for ControlError {
50 fn from(err: RustdocParseError) -> Self {
51 Self::RustdocParse(err)
52 }
53}
54
55impl From<StoreError> for ControlError {
56 fn from(err: StoreError) -> Self {
57 Self::Store(err)
58 }
59}
60
61pub struct DocxControlPlane<C: Connection> {
63 store: SurrealDocStore<C>,
64}
65
66impl<C: Connection> Clone for DocxControlPlane<C> {
67 fn clone(&self) -> Self {
68 Self {
69 store: self.store.clone(),
70 }
71 }
72}
73
74impl<C: Connection> DocxControlPlane<C> {
75 #[must_use]
77 pub fn new(db: Surreal<C>) -> Self {
78 Self {
79 store: SurrealDocStore::new(db),
80 }
81 }
82
83 #[must_use]
85 pub fn from_arc(db: Arc<Surreal<C>>) -> Self {
86 Self {
87 store: SurrealDocStore::from_arc(db),
88 }
89 }
90
91 #[must_use]
93 pub const fn with_store(store: SurrealDocStore<C>) -> Self {
94 Self { store }
95 }
96
97 #[must_use]
99 pub const fn store(&self) -> &SurrealDocStore<C> {
100 &self.store
101 }
102}