pub trait Buildpack {
type Platform: Platform;
type Metadata: DeserializeOwned;
type Error: Debug;
// Required methods
fn detect(
&self,
context: DetectContext<Self>,
) -> Result<DetectResult, Self::Error>;
fn build(
&self,
context: BuildContext<Self>,
) -> Result<BuildResult, Self::Error>;
// Provided method
fn on_error(&self, error: Error<Self::Error>) { ... }
}Expand description
Represents a buildpack written with the libcnb framework.
To implement a buildpack with this framework, start by implementing this trait. Besides the main
build and detect methods, it also holds associated types for the buildpack: the Platform it
is targeting, the type for its metadata and the custom error type.
Required Associated Types§
sourcetype Platform: Platform
type Platform: Platform
The platform targeted by this buildpack. If no specific platform is targeted, consider using
GenericPlatform as the type.
sourcetype Metadata: DeserializeOwned
type Metadata: DeserializeOwned
The metadata type for this buildpack. This is the data within [metadata] of the buildpacks
buildpack.toml. The framework will attempt to parse the data and will only continue if
parsing succeeded. If you wish to use raw, untyped, TOML data instead, use
GenericMetadata.
sourcetype Error: Debug
type Error: Debug
The error type for buildpack specific errors, usually an enum. Examples of values inside the
enum are: MavenExecutionFailed, InvalidGemfileLock, IncompatiblePythonVersion. The
framework itself has its own error type that contains more low-level errors that can occur
during buildpack execution.
Required Methods§
sourcefn detect(
&self,
context: DetectContext<Self>,
) -> Result<DetectResult, Self::Error>
fn detect( &self, context: DetectContext<Self>, ) -> Result<DetectResult, Self::Error>
Detect logic for this buildpack. Directly corresponds to detect in the CNB buildpack interface.
sourcefn build(&self, context: BuildContext<Self>) -> Result<BuildResult, Self::Error>
fn build(&self, context: BuildContext<Self>) -> Result<BuildResult, Self::Error>
Build logic for this buildpack. Directly corresponds to build in the CNB buildpack interface.
Provided Methods§
sourcefn on_error(&self, error: Error<Self::Error>)
fn on_error(&self, error: Error<Self::Error>)
If an unhandled error occurred within the framework or the buildpack, this method will be called by the framework to allow custom, buildpack specific, code to run before exiting. Usually, this method is implemented by logging the error in a user friendly manner.
Implementations are not limited to just logging, for example, buildpacks might want to collect and send metrics about occurring errors to a central system.
The default implementation will simply print the error
(using its Debug implementation) to stderr.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.