Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 8 additions & 17 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[workspace]
resolver = "2"
members = [
"usage",
"cache_diff",
"cache_diff_derive",
]
Expand Down
4 changes: 4 additions & 0 deletions cache_diff/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ documentation.workspace = true
cache_diff_derive = { version = "1" , optional = true, path = "../cache_diff_derive" }
bullet_stream = { version = "0", optional = true }

[dev-dependencies]
trybuild = "1.0.104"
serde.workspace = true

[features]
default = ["derive"]
derive = ["dep:cache_diff_derive"]
Expand Down
1 change: 1 addition & 0 deletions cache_diff/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,4 +252,5 @@ pub trait CacheDiff {
format!("`{}`", value)
}
}
#[cfg(feature = "derive")]
pub use cache_diff_derive::CacheDiff;
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
error: Unknown cache_diff attribute: `custom`. Must be one of `rename`, `display`, `ignore`
--> tests/fails/accidental_custom_field.rs:5:18
|
5 | #[cache_diff(custom = function)]
| ^^^^^^

error:
The cache_diff attribute `custom` is available on the struct, not the field
--> tests/fails/accidental_custom_field.rs:5:18
|
Expand Down
9 changes: 9 additions & 0 deletions cache_diff/tests/fails/duplicate_field.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use cache_diff::CacheDiff;

#[derive(CacheDiff)]
struct CustomDiffFn {
#[cache_diff(rename = "foo", rename = "bar")]
name: String,
}

fn main() {}
11 changes: 11 additions & 0 deletions cache_diff/tests/fails/duplicate_field.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
error: CacheDiff duplicate attribute: `rename`
--> tests/fails/duplicate_field.rs:5:34
|
5 | #[cache_diff(rename = "foo", rename = "bar")]
| ^^^^^^

error: previously `rename` defined here
--> tests/fails/duplicate_field.rs:5:18
|
5 | #[cache_diff(rename = "foo", rename = "bar")]
| ^^^^^^
13 changes: 13 additions & 0 deletions cache_diff/tests/fails/missing_custom.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
error: `Expected `MissingCustom` to implement the `custom` attribute `#[cache_diff(custom = <function>)]`, but it does not
--> tests/fails/missing_custom.rs:3:10
|
3 | #[derive(CacheDiff)]
| ^^^^^^^^^
|
= note: this error originates in the derive macro `CacheDiff` (in Nightly builds, run with -Z macro-backtrace for more info)

error: Field `i_am_a_custom_field` is ignored and requires `MissingCustom` to implement `custom`
--> tests/fails/missing_custom.rs:6:5
|
6 | i_am_a_custom_field: String,
| ^^^^^^^^^^^^^^^^^^^
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ error[E0277]: `NotDisplay` doesn't implement `std::fmt::Display`
= note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
= note: required for `&NotDisplay` to implement `std::fmt::Display`
note: required by a bound in `fmt_value`
--> $WORKSPACE/cache_diff/src/lib.rs
--> src/lib.rs
|
| fn fmt_value<T: std::fmt::Display>(&self, value: &T) -> String {
| ^^^^^^^^^^^^^^^^^ required by this bound in `CacheDiff::fmt_value`
Expand Down
22 changes: 22 additions & 0 deletions cache_diff/tests/pass/struct_with_generics.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use cache_diff::CacheDiff;

#[derive(CacheDiff)]
struct Example<T>
where
T: std::fmt::Display + Eq,
{
name: String,
other: T,
}

fn main() {
let now = Example::<String> {
name: "Richard".to_string(),
other: "John Jacob Jingleheimer Schmidt (his name is my name too)".to_string(),
};

let _ = now.diff(&Example::<String> {
name: "Richard".to_string(),
other: "schneems".to_string(),
});
}
2 changes: 1 addition & 1 deletion cache_diff_derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ quote = "1.0"
syn = { version = "2.0", features = ["extra-traits"] }
proc-macro2 = "1.0"
bullet_stream = { version = "0", optional = true }
strum = {version = "0.26", features = ["derive"] }
strum = {version = "0.27", features = ["derive"] }

[lib]
proc-macro = true
Expand Down
Loading