diff --git a/CHANGELOG.md b/CHANGELOG.md index 692dad2d..fb66cb5c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `libcnb-cargo`: - No longer outputs paths for non-libcnb.rs and non-meta buildpacks. ([#657](https://github.com/heroku/libcnb.rs/pull/657)) - Build output for humans changed slightly, output intended for machines/scripting didn't change. ([#657](https://github.com/heroku/libcnb.rs/pull/657)) +- `libcnb`: + - The `Layer` trait interface now takes a mutable reference. Buildpack authors will need to change `&self` to `&mut self` for all their layers. ([#669](https://github.com/heroku/libcnb.rs/pull/669)) ## [0.14.0] - 2023-08-18 diff --git a/examples/execd/src/layer.rs b/examples/execd/src/layer.rs index 6c2fea3f..fbf4a124 100644 --- a/examples/execd/src/layer.rs +++ b/examples/execd/src/layer.rs @@ -21,7 +21,7 @@ impl Layer for ExecDLayer { } fn create( - &self, + &mut self, _context: &BuildContext, _layer_path: &Path, ) -> Result, ::Error> { diff --git a/examples/ruby-sample/src/layers/bundler.rs b/examples/ruby-sample/src/layers/bundler.rs index 726a0607..49f5d189 100644 --- a/examples/ruby-sample/src/layers/bundler.rs +++ b/examples/ruby-sample/src/layers/bundler.rs @@ -31,7 +31,7 @@ impl Layer for BundlerLayer { } fn create( - &self, + &mut self, context: &BuildContext, layer_path: &Path, ) -> Result, RubyBuildpackError> { @@ -69,7 +69,7 @@ impl Layer for BundlerLayer { } fn existing_layer_strategy( - &self, + &mut self, context: &BuildContext, layer: &LayerData, ) -> Result { @@ -85,7 +85,7 @@ impl Layer for BundlerLayer { } fn update( - &self, + &mut self, context: &BuildContext, layer: &LayerData, ) -> Result, RubyBuildpackError> { diff --git a/examples/ruby-sample/src/layers/ruby.rs b/examples/ruby-sample/src/layers/ruby.rs index 07c6608f..26ee25fe 100644 --- a/examples/ruby-sample/src/layers/ruby.rs +++ b/examples/ruby-sample/src/layers/ruby.rs @@ -23,7 +23,7 @@ impl Layer for RubyLayer { } fn create( - &self, + &mut self, context: &BuildContext, layer_path: &Path, ) -> Result, RubyBuildpackError> { diff --git a/libcnb/src/build.rs b/libcnb/src/build.rs index bedaac4b..46a58838 100644 --- a/libcnb/src/build.rs +++ b/libcnb/src/build.rs @@ -85,7 +85,7 @@ impl BuildContext { /// # } /// # /// fn create( - /// &self, + /// &mut self, /// context: &BuildContext, /// layer_path: &Path, /// ) -> Result, ::Error> { diff --git a/libcnb/src/layer/handling.rs b/libcnb/src/layer/handling.rs index 127536a0..495aabf7 100644 --- a/libcnb/src/layer/handling.rs +++ b/libcnb/src/layer/handling.rs @@ -21,10 +21,10 @@ use std::path::{Path, PathBuf}; pub(crate) fn handle_layer>( context: &BuildContext, layer_name: LayerName, - layer: L, + mut layer: L, ) -> Result, HandleLayerErrorOrBuildpackError> { match read_layer(&context.layers_dir, &layer_name) { - Ok(None) => handle_create_layer(context, &layer_name, &layer), + Ok(None) => handle_create_layer(context, &layer_name, &mut layer), Ok(Some(layer_data)) => { let existing_layer_strategy = layer .existing_layer_strategy(context, &layer_data) @@ -33,9 +33,11 @@ pub(crate) fn handle_layer>( match existing_layer_strategy { ExistingLayerStrategy::Recreate => { delete_layer(&context.layers_dir, &layer_name)?; - handle_create_layer(context, &layer_name, &layer) + handle_create_layer(context, &layer_name, &mut layer) + } + ExistingLayerStrategy::Update => { + handle_update_layer(context, &layer_data, &mut layer) } - ExistingLayerStrategy::Update => handle_update_layer(context, &layer_data, &layer), ExistingLayerStrategy::Keep => { // We need to rewrite the metadata even if we just want to keep the layer around // since cached layers are restored without their types, causing the layer to be @@ -106,7 +108,7 @@ pub(crate) fn handle_layer>( fn handle_create_layer>( context: &BuildContext, layer_name: &LayerName, - layer: &L, + layer: &mut L, ) -> Result, HandleLayerErrorOrBuildpackError> { let layer_dir = context.layers_dir.join(layer_name.as_str()); @@ -138,7 +140,7 @@ fn handle_create_layer>( fn handle_update_layer>( context: &BuildContext, layer_data: &LayerData, - layer: &L, + layer: &mut L, ) -> Result, HandleLayerErrorOrBuildpackError> { let layer_result = layer .update(context, layer_data) diff --git a/libcnb/src/layer/public_interface.rs b/libcnb/src/layer/public_interface.rs index 2f835041..09b1e452 100644 --- a/libcnb/src/layer/public_interface.rs +++ b/libcnb/src/layer/public_interface.rs @@ -45,7 +45,7 @@ pub trait Layer { /// # Implementation Requirements /// Implementations **MUST NOT** write to any other location than `layer_path`. fn create( - &self, + &mut self, context: &BuildContext, layer_path: &Path, ) -> Result, ::Error>; @@ -74,7 +74,7 @@ pub trait Layer { /// # Implementation Requirements /// Implementations **MUST NOT** modify the file-system. fn existing_layer_strategy( - &self, + &mut self, context: &BuildContext, layer_data: &LayerData, ) -> Result::Error> { @@ -100,7 +100,7 @@ pub trait Layer { /// # Implementation Requirements /// Implementations **MUST NOT** write to any other location than `layer_path`. fn update( - &self, + &mut self, context: &BuildContext, layer_data: &LayerData, ) -> Result, ::Error> { diff --git a/libcnb/src/layer/tests.rs b/libcnb/src/layer/tests.rs index b225c200..4156cbc2 100644 --- a/libcnb/src/layer/tests.rs +++ b/libcnb/src/layer/tests.rs @@ -61,7 +61,7 @@ impl Layer for TestLayer { } fn create( - &self, + &mut self, _context: &BuildContext, layer_path: &Path, ) -> Result, ::Error> { @@ -79,7 +79,7 @@ impl Layer for TestLayer { } fn existing_layer_strategy( - &self, + &mut self, _context: &BuildContext, _layer_data: &LayerData, ) -> Result::Error> { @@ -87,7 +87,7 @@ impl Layer for TestLayer { } fn update( - &self, + &mut self, _context: &BuildContext, layer_data: &LayerData, ) -> Result, ::Error> { @@ -749,7 +749,7 @@ fn default_layer_method_implementations() { } fn create( - &self, + &mut self, _context: &BuildContext, _layer_path: &Path, ) -> Result, ::Error> { @@ -770,7 +770,7 @@ fn default_layer_method_implementations() { let temp_dir = tempdir().unwrap(); let context = build_context(&temp_dir); let layer_name = random_layer_name(); - let simple_layer = SimpleLayer; + let mut simple_layer = SimpleLayer; let simple_layer_metadata = SimpleLayerMetadata { field_one: String::from("value one"), @@ -837,7 +837,7 @@ fn layer_env_read_write() { } fn create( - &self, + &mut self, _context: &BuildContext, _layer_path: &Path, ) -> Result, ::Error> { @@ -847,7 +847,7 @@ fn layer_env_read_write() { } fn existing_layer_strategy( - &self, + &mut self, _context: &BuildContext, layer_data: &LayerData, ) -> Result::Error> { @@ -857,7 +857,7 @@ fn layer_env_read_write() { } fn update( - &self, + &mut self, _context: &BuildContext, layer_data: &LayerData, ) -> Result, ::Error> { diff --git a/test-buildpacks/readonly-layer-files/src/layer.rs b/test-buildpacks/readonly-layer-files/src/layer.rs index 7beb18db..04e384f4 100644 --- a/test-buildpacks/readonly-layer-files/src/layer.rs +++ b/test-buildpacks/readonly-layer-files/src/layer.rs @@ -24,7 +24,7 @@ impl Layer for TestLayer { } fn create( - &self, + &mut self, _context: &BuildContext, layer_path: &Path, ) -> Result, ::Error> { @@ -42,7 +42,7 @@ impl Layer for TestLayer { } fn existing_layer_strategy( - &self, + &mut self, _context: &BuildContext, _layer_data: &LayerData, ) -> Result::Error> { diff --git a/test-buildpacks/sbom/src/test_layer.rs b/test-buildpacks/sbom/src/test_layer.rs index 73c3862b..a9af857a 100644 --- a/test-buildpacks/sbom/src/test_layer.rs +++ b/test-buildpacks/sbom/src/test_layer.rs @@ -22,7 +22,7 @@ impl Layer for TestLayer { } fn create( - &self, + &mut self, _context: &BuildContext, _layer_path: &Path, ) -> Result, ::Error> { @@ -43,7 +43,7 @@ impl Layer for TestLayer { } fn existing_layer_strategy( - &self, + &mut self, _context: &BuildContext, _layer_data: &LayerData, ) -> Result::Error> { @@ -51,7 +51,7 @@ impl Layer for TestLayer { } fn update( - &self, + &mut self, _context: &BuildContext, _layer_data: &LayerData, ) -> Result, ::Error> { diff --git a/test-buildpacks/sbom/src/test_layer_2.rs b/test-buildpacks/sbom/src/test_layer_2.rs index 2c5e7b88..586ef82c 100644 --- a/test-buildpacks/sbom/src/test_layer_2.rs +++ b/test-buildpacks/sbom/src/test_layer_2.rs @@ -22,7 +22,7 @@ impl Layer for TestLayer2 { } fn create( - &self, + &mut self, _context: &BuildContext, _layer_path: &Path, ) -> Result, ::Error> { @@ -43,7 +43,7 @@ impl Layer for TestLayer2 { } fn existing_layer_strategy( - &self, + &mut self, _context: &BuildContext, _layer_data: &LayerData, ) -> Result::Error> {