pub trait ResourceBuilder: Default {
    type Config: Serialize;
    type Output: Serialize + DeserializeOwned;

    const TYPE: Type;

    // Required methods
    fn config(&self) -> &Self::Config;
    fn output<'life0, 'async_trait>(
        self,
        factory: &'life0 mut dyn Factory
    ) -> Pin<Box<dyn Future<Output = Result<Self::Output, Error>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             Self: 'async_trait;
}
Expand description

Allows implementing plugins for the Shuttle main function.

§Creating your own Shuttle plugin

You can add your own implementation of this trait along with IntoResource<R> to customize the input type R that gets into the Shuttle main function on an existing resource. The Factory in ResourceBuilder::output can be used to provision resources on Shuttle’s servers if your service will need any.

You can also make your own plugin, for example to generalise the connection logic to a third-party service. One example of this is shuttle-qdrant.

Please refer to shuttle-examples/custom-resource for examples of how to create a custom resource. For more advanced provisioning of custom resources, please get in touch and detail your use case. We’ll be interested to see what you want to provision and how to do it on your behalf on the fly.

Required Associated Types§

source

type Config: Serialize

The input config to this resource.

source

type Output: Serialize + DeserializeOwned

The output from requesting this resource. A cached copy of this will be used if the same ResourceBuilder::Config is found for this ResourceBuilder::TYPE.

Required Associated Constants§

source

const TYPE: Type

The type of resource this plugin creates. If dealing with a Shuttle-provisioned resource, such as a database, use the corresponding variant. Otherwise, use the Custom variant.

Required Methods§

source

fn config(&self) -> &Self::Config

Get the config of this plugin after it has been built from its macro arguments with the builder pattern.

If the exact same config was returned by a previous deployment that used this resource, then ResourceBuilder::output will not be called to get the builder output again. Rather the output state of the previous deployment will be passed to [ResourceBuilder::build].

source

fn output<'life0, 'async_trait>( self, factory: &'life0 mut dyn Factory ) -> Pin<Box<dyn Future<Output = Result<Self::Output, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, Self: 'async_trait,

Construct this resource with the help of metadata and by calling provisioner methods in the Factory.

This method is where the actual resource provisioning should take place and is expected to take the longest. It can at times even take minutes. That is why the output of this method is cached and calling this method can be skipped as explained in ResourceBuilder::config.

The output from this function is passed to IntoResource::into_resource.

Object Safety§

This trait is not object safe.

Implementors§