Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot todo the invalid_metadata_action #859

Open
schneems opened this issue Sep 9, 2024 · 1 comment
Open

Cannot todo the invalid_metadata_action #859

schneems opened this issue Sep 9, 2024 · 1 comment

Comments

@schneems
Copy link
Contributor

schneems commented Sep 9, 2024

Expected

I expect I can use todo!() for any function to make it compile while I work on refining my logic in another area.

Actual

This code that returns an explicit InvalidMetadataAction compiles:

pub(crate) fn install_ruby(
    context: &BuildContext<RubyBuildpack>,
    mut bullet: Print<SubBullet<Stdout>>,
    new_metadata: RubyInstallLayerMetadata,
) -> Result<(Print<SubBullet<Stdout>>, LayerEnv), libcnb::Error<RubyBuildpackError>> {
    let layer = context.cached_layer(
        layer_name!("ruby"),
        CachedLayerDefinition {
            build: true,
            launch: true,
            invalid_metadata_action: &|_| InvalidMetadataAction::DeleteLayer,

            // invalid_metadata_action: &|invalid_metadata| {
            //     todo!();
            // },
            restored_layer_action: &|old_metadata: &RubyInstallLayerMetadata, _| {
                if old_metadata == &new_metadata {
                    RestoredLayerAction::KeepLayer
                } else {
                    RestoredLayerAction::DeleteLayer
                }
            },
        },
    )?;

    match layer.state {
        LayerState::Restored { .. } => {
            //
        }
        LayerState::Empty { .. } => {
            //
        }
    };

    Ok((bullet, layer.read_env()?))
}

This code that replaces it with a todo!() does not:

pub(crate) fn install_ruby(
    context: &BuildContext<RubyBuildpack>,
    mut bullet: Print<SubBullet<Stdout>>,
    new_metadata: RubyInstallLayerMetadata,
) -> Result<(Print<SubBullet<Stdout>>, LayerEnv), libcnb::Error<RubyBuildpackError>> {
    let layer = context.cached_layer(
        layer_name!("ruby"),
        CachedLayerDefinition {
            build: true,
            launch: true,
            // invalid_metadata_action: &|_| InvalidMetadataAction::DeleteLayer,
            invalid_metadata_action: &|invalid_metadata| {
                todo!();
            },
            restored_layer_action: &|old_metadata: &RubyInstallLayerMetadata, _| {
                if old_metadata == &new_metadata {
                    RestoredLayerAction::KeepLayer
                } else {
                    RestoredLayerAction::DeleteLayer
                }
            },
        },
    )?;

    match layer.state {
        LayerState::Restored { .. } => {
            //
        }
        LayerState::Empty { .. } => {
            //
        }
    };

    Ok((bullet, layer.read_env()?))
}

With output:

   Compiling heroku-ruby-buildpack v0.0.0 (/Users/rschneeman/Documents/projects/work/buildpacks-ruby/buildpacks/ruby)
error: could not compile `heroku-ruby-buildpack` (bin "heroku-ruby-buildpack" test) due to 2 previous errors; 87 warnings emitted
warning: build failed, waiting for other jobs to finish...
error: could not compile `heroku-ruby-buildpack` (bin "heroku-ruby-buildpack") due to 2 previous errors; 87 warnings emitted
error[E0277]: the trait bound `(): IntoAction<libcnb::layer::InvalidMetadataAction<RubyInstallLayerMetadataV2>, _, RubyBuildpackError>` is not satisfied
   --> buildpacks/ruby/src/layers/ruby_install_layer.rs:54:25
    |
54  |     let layer = context.cached_layer(
    |                         ^^^^^^^^^^^^ the trait `IntoAction<libcnb::layer::InvalidMetadataAction<RubyInstallLayerMetadataV2>, _, RubyBuildpackError>` is not implemented for `()`
    |
    = help: the trait `IntoAction<libcnb::layer::InvalidMetadataAction<RubyInstallLayerMetadataV2>, _, RubyBuildpackError>` is implemented for `(libcnb::layer::InvalidMetadataAction<RubyInstallLayerMetadataV2>, _)`
    = help: for that trait implementation, expected `(libcnb::layer::InvalidMetadataAction<RubyInstallLayerMetadataV2>, _)`, found `()`
note: required by a bound in `BuildContext::<B>::cached_layer`
   --> /Users/rschneeman/.cargo/registry/src/index.crates.io-6f17d22bba15001f/libcnb-0.23.0/src/build.rs:363:18
    |
356 |     pub fn cached_layer<'a, M, MA, RA, MAC, RAC>(
    |            ------------ required by a bound in this associated function
...
363 |         MA: 'a + IntoAction<InvalidMetadataAction<M>, MAC, B::Error>,
    |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `BuildContext::<B>::cached_layer`

error[E0277]: the trait bound `(): IntoAction<libcnb::layer::InvalidMetadataAction<ruby_install_layer::RubyInstallLayerMetadataV2>, _, RubyBuildpackError>` is not satisfied
   --> buildpacks/ruby/src/layers/ruby_install_layer.rs:54:25
    |
54  |     let layer = context.cached_layer(
    |                         ^^^^^^^^^^^^ the trait `IntoAction<libcnb::layer::InvalidMetadataAction<ruby_install_layer::RubyInstallLayerMetadataV2>, _, RubyBuildpackError>` is not implemented for `()`
    |
    = help: the trait `IntoAction<libcnb::layer::InvalidMetadataAction<ruby_install_layer::RubyInstallLayerMetadataV2>, _, RubyBuildpackError>` is implemented for `(libcnb::layer::InvalidMetadataAction<ruby_install_layer::RubyInstallLayerMetadataV2>, _)`
    = help: for that trait implementation, expected `(libcnb::layer::InvalidMetadataAction<ruby_install_layer::RubyInstallLayerMetadataV2>, _)`, found `()`
note: required by a bound in `BuildContext::<B>::cached_layer`
   --> /Users/rschneeman/.cargo/registry/src/index.crates.io-6f17d22bba15001f/libcnb-0.23.0/src/build.rs:363:18
    |
356 |     pub fn cached_layer<'a, M, MA, RA, MAC, RAC>(
    |            ------------ required by a bound in this associated function
...
363 |         MA: 'a + IntoAction<InvalidMetadataAction<M>, MAC, B::Error>,
    |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `BuildContext::<B>::cached_layer`

[Finished running. Exit status: 101]
@schneems
Copy link
Contributor Author

schneems commented Sep 9, 2024

A workaround is to have it return InvalidMetadataAction::DeleteLayer after the todo!().

I'm not sure if we can otherwise improve the experience. Can we implement IntoAction<T, _, _> for () ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant