shuttle_runtime/
lib.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#![doc = include_str!("../README.md")]
#![doc(
    html_logo_url = "https://raw.githubusercontent.com/shuttle-hq/shuttle/main/assets/logo-square-transparent.png",
    html_favicon_url = "https://raw.githubusercontent.com/shuttle-hq/shuttle/main/assets/favicon.ico"
)]

/// shuttle.rs runtime
mod alpha;
/// Built-in plugins
mod plugins;
/// shuttle.dev runtime
mod rt;
mod start;

// Public API
pub use plugins::{Metadata, Secrets};
pub use shuttle_codegen::main;
pub use shuttle_service::{
    CustomError, DbInput, DeploymentMetadata, Environment, Error, IntoResource, ResourceFactory,
    ResourceInputBuilder, SecretStore, Service,
};

// Useful re-exports
pub use async_trait::async_trait;
pub use tokio;

const VERSION_STRING: &str = concat!(env!("CARGO_PKG_NAME"), " ", env!("CARGO_PKG_VERSION"));

// Not part of public API
#[doc(hidden)]
pub mod __internals {
    // Internals used by the codegen
    pub use crate::start::start;

    // Dependencies required by the codegen
    pub use anyhow::Context;
    pub use serde_json;
    pub use strfmt::strfmt;

    use super::*;
    use std::future::Future;
    #[async_trait]
    pub trait Loader {
        async fn load(self, factory: ResourceFactory) -> Result<Vec<Vec<u8>>, Error>;
    }

    #[async_trait]
    impl<F, O> Loader for F
    where
        F: FnOnce(ResourceFactory) -> O + Send,
        O: Future<Output = Result<Vec<Vec<u8>>, Error>> + Send,
    {
        async fn load(self, factory: ResourceFactory) -> Result<Vec<Vec<u8>>, Error> {
            (self)(factory).await
        }
    }

    #[async_trait]
    pub trait Runner {
        type Service: Service;

        async fn run(self, resources: Vec<Vec<u8>>) -> Result<Self::Service, Error>;
    }

    #[async_trait]
    impl<F, O, S> Runner for F
    where
        F: FnOnce(Vec<Vec<u8>>) -> O + Send,
        O: Future<Output = Result<S, Error>> + Send,
        S: Service,
    {
        type Service = S;

        async fn run(self, resources: Vec<Vec<u8>>) -> Result<Self::Service, Error> {
            (self)(resources).await
        }
    }
}