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

Experimental interface demonstration #377

Closed

Conversation

schneems
Copy link
Contributor

This PR demonstrates using the bon crate to turn a function into a "builder" using the type/state pattern that can later be called.

There are two commits a "simple" and an "advanced" version where everything is customizable.

Here's what a function turned into a builder via `bon` would look like
We could take the builder idea to an extreme and allow for BYO functions provided they have the same return type. These would basically be equivalent:

```rust
    // Fully spelled out
    let _ = cache_layer_builder()
        .on_invalid_metadata(&invalid_metadata_action)
        .on_restored_layer(&|old, _| restored_layer_action(old, metadata))
        .layer_name(layer_name!("ruby"))
        .metadata(metadata)
        .context(context)
        .launch(true)
        .build(true)
        .call()?;

    // With defaults
    let layer_ref = cache_layer_builder()
        .layer_name(layer_name!("ruby"))
        .metadata(metadata)
        .context(context)
        .call()?;
```

This also allows for skipping writing metadata so it's totally configurable.

If we went this route, we could rename it to something more generic like simply `cache_layer` or maybe `cache_layer_builder`. The module name could be significant, maybe something like `diff_migrate_cache::layer_builder. Naming is hard.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant