Skip to content

Commit b790763

Browse files
authored
Fix multiple derive calls in the same file (#4)
* Fix multiple derive calls in the same file I emulated the `use` line off of a similar `extern` line from serde, don't entirely remember the reason why. I can use the full path to the trait and we don't need to import/use anything. This fixes issue #3 Close #3 * Rev-version
1 parent 7893f49 commit b790763

File tree

5 files changed

+40
-6
lines changed

5 files changed

+40
-6
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
## Unreleased
22

3+
- Fix: Multiple `#[derive(CachDiff)]` calls in the same file now work (https://github.com/heroku-buildpacks/cache_diff/pull/4)
4+
35
## 1.0.0
46

57
- Changed: Error when deriving CacheDiff when zero comparison fields are found. This can happen if the struct has no fields or if all fields are `ignore`-d (https://github.com/schneems/cache_diff/pull/4)

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ members = [
77
]
88

99
[workspace.package]
10-
version = "1.0.0"
10+
version = "1.0.1"
1111
rust-version = "1.82"
1212
edition = "2021"
1313
license = "Apache-2.0"

cache_diff_derive/src/fields.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,7 @@ pub fn create_cache_diff(item: TokenStream) -> syn::Result<TokenStream> {
105105
))
106106
} else {
107107
Ok(quote! {
108-
#[allow(clippy::useless_attribute)]
109-
use cache_diff as _cache_diff;
110-
impl _cache_diff::CacheDiff for #struct_identifier {
108+
impl cache_diff::CacheDiff for #struct_identifier {
111109
fn diff(&self, old: &Self) -> Vec<String> {
112110
let mut differences = Vec::new();
113111
#(#comparisons)*

usage/src/multiple_structs.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Ensure multiple derives can be in the same file
2+
#[derive(CacheDiff)]
3+
struct Dog {
4+
woof: String,
5+
}
6+
#[allow(dead_code)]
7+
#[derive(CacheDiff)]
8+
struct Cat {
9+
meow: String,
10+
}
11+
#[cfg(test)]
12+
mod test {
13+
use super::*;
14+
#[test]
15+
fn test_cat() {
16+
let diff = Cat {
17+
meow: "Meow".to_string(),
18+
}
19+
.diff(&Cat {
20+
meow: "Woem".to_string(),
21+
});
22+
assert!(diff.len() == 1);
23+
}
24+
#[test]
25+
fn test_dog() {
26+
let diff = Dog {
27+
woof: "Woof".to_string(),
28+
}
29+
.diff(&Dog {
30+
woof: "Foow".to_string(),
31+
});
32+
assert!(diff.len() == 1);
33+
}
34+
}

0 commit comments

Comments
 (0)