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

Add custom = <function> container attribute and allow optional ignore = "<reason>" for fields #6

Merged
merged 6 commits into from
Jan 29, 2025

Conversation

schneems
Copy link
Contributor

@schneems schneems commented Jan 25, 2025

  • Add #[cache_diff(custom = <function>)] to containers (structs) to allow for customizing + deriving diffs.
  • Add: Allow annotating ignored fields with #[cache_diff(ignore = "<reason>")]. Using ignore = "custom" requires the container (struct) to implement custom = <function>.

For a real-life test drive you can see heroku/buildpacks-go#327 which uses this branch. Overall I'm pretty confident and happy with the state of this PR and feel it's ready for merge pending user feedback or doc fixups.

How to review suggestions

  • Look at the example code and tests.
    • Read the failure messages: do they make sense
  • Read the user facing docs (readme/lib.rs) do they make sense?

Please mark non-blocking comments/feedback as such.

See the module docs. Basically, we allow bypassing the built-in parsing to customize one or more attributes. If you're going to customize all of them, then there's no point in using the derive macro, however I found there are cases where all but one attribute can be derived, and it stinks to resort to needing to manually re-implement when that happens.
Allows someone to leave behind a comment for why something is ignored as well as if someone uses `ignore = "custom"` we'll enforce that the struct must have a `cache_diff(custom = <function>)` defined on the struct.
@schneems schneems marked this pull request as ready for review January 25, 2025 18:38
@schneems schneems requested a review from a team as a code owner January 25, 2025 18:38
Trying to get version resolution with the build packs-ruby crate to work with manually specified git

```
cache_diff = { features = ["bullet_stream"], branch = "schneems/custom_fn", git = "https://github.com/heroku-buildpacks/cache_diff" }
```

Not sure if it will work.
Even though the derive macro knows which attributes it owns:

```
#[proc_macro_derive(CacheDiff, attributes(cache_diff))]
pub fn cache_diff(item: TokenStream) -> TokenStream {
    //...
}
```

It passes in the full AST. The non-cache-diff attributes must be filtered out. This is how the `CacheDiffAttributes` (which holds Field attributes) is implemented.
@schneems schneems merged commit c560b45 into main Jan 29, 2025
4 checks passed
@schneems schneems deleted the schneems/custom_fn branch January 29, 2025 10:49
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

Successfully merging this pull request may close these issues.

2 participants