Skip to main content

cartel_sqlite/open/
mod.rs

1use dope_core::driver::settings::{claim, errors};
2mod error;
3pub mod journal;
4
5use crate::{api, catalogs, conn, runtime};
6use dope_core::driver::settings;
7use dope_runtime::{executor::boot, topology};
8use std::marker;
9
10pub use error::Error;
11
12/// Owns cleanup errors delivered after an installation releases its native resources.
13#[derive(Debug, Default)]
14pub struct Completion {
15    errors: Option<(crate::Error, Option<crate::Error>)>,
16}
17
18impl Completion {
19    pub const fn new() -> Self {
20        Self { errors: None }
21    }
22
23    /// Takes every retained error in observation order, allowing this sink to be reused.
24    pub fn take(&mut self) -> Result<(), (crate::Error, Option<crate::Error>)> {
25        match self.errors.take() {
26            None => Ok(()),
27            Some(errors) => Err(errors),
28        }
29    }
30
31    pub(crate) fn admit(&mut self) -> Result<&mut Self, Error> {
32        if self.errors.is_some() {
33            return Err(Error::Unobserved);
34        }
35        Ok(self)
36    }
37
38    pub(crate) fn complete(&mut self, errors: (crate::Error, Option<crate::Error>)) {
39        self.errors = Some(errors);
40    }
41}
42
43pub struct Plan<I> {
44    catalog: marker::PhantomData<fn() -> I>,
45}
46
47impl<I> Plan<I> {
48    pub(crate) const fn new() -> Self {
49        Self {
50            catalog: marker::PhantomData,
51        }
52    }
53}
54
55impl<I> settings::Resource for Plan<I> {
56    fn include_in(&self, needs: claim::Needs) -> Result<claim::Needs, errors::Claim> {
57        Ok(needs)
58    }
59}
60
61impl<I: catalogs::Catalog> Plan<I> {
62    /// Delivers retained cleanup errors to `report` after this installation is dropped.
63    pub fn install<'local, 'scope, 'life, 'p, 'd, Q>(
64        self,
65        stage: &topology::Boot<'_, 'scope, 'life, 'p, 'd, runtime::Layout<'_, I>, Q>,
66        report: &'local mut Completion,
67    ) -> impl boot::Root<'d, Output = Result<conn::Installed<'local, 'd, I>, Error>>
68    + use<'local, 'd, I, Q>
69    where
70        'd: 'p,
71        'p: 'life,
72        'life: 'scope + 'local,
73    {
74        api::Open::new(stage.pinned(), report)
75    }
76}