I'm a software and full-stack web developer.
Fun | Facts |
---|---|
Favorite language | Rust ๐ฆ |
Favorite activities | Hiking, Classical Music ๐ผ, ๐น |
Favorite composers | Prokofiev, Beethoven |
Rust trait for diffing and applying diffs between data structures
License: MIT License
I like this crate. Thank you for making it.
Are you considering adding the diffing of enum
s?
If so, would it help if I wrote a set of tests?
If so, where do I branch off, and how do I name the branch before I submit a pull request?
This would likely involve adding an alloc
and std
feature.
Hello @benhall-7 ,
Playing with the lib I've come across inconsistent behavior for structs containing String
types.
Example:
use diff::Diff;
#[derive(Debug, PartialEq, Diff)]
#[diff(attr(
#[derive(Debug, PartialEq)]
))]
struct OptionalInteger {
x: i32,
ox: Option<i32>,
}
#[derive(Debug, PartialEq, Diff)]
#[diff(attr(
#[derive(Debug, PartialEq)]
))]
struct OptionalString {
x: String,
ox: Option<String>,
}
fn main() {
let empty_integer = OptionalInteger { x: 42, ox: None };
let filled_integer = OptionalInteger { x: 42, ox: Some(42)};
let di = empty_integer.diff(&filled_integer);
println!("{:#?}", di);
let empty_string = OptionalString { x: "42".to_string(), ox: None};
let filled_string = OptionalString { x: "42".to_string(), ox: Some("42".to_string())};
let ds = empty_string.diff(&filled_string);
println!("{:#?}", ds);
}
Expected output:
OptionalIntegerDiff {
x: 0,
ox: Some(
42,
),
}
OptionalStringDiff {
x: None,
ox: Some(
"42",
),
}
Actual output (note how instead of Some(String)
we're getting Some(Some(String))
OptionalIntegerDiff {
x: 0,
ox: Some(
42,
),
}
OptionalStringDiff {
x: None,
ox: Some(
Some(
"42",
),
),
}
Make it Option<Vec<String>>
(or other compound type for that matter) and the end result is even more interesting.
As far as I understand, it is not possible to derive diff on struct with PhantomData
field(s).
It might be reasonable to just ignore PhantomData
(and maybe some other types?) in order to make it possible to derive Diff
The resulting Diff struct from using the derive macro does not implement Debug, it would be nice for, debugging...
Dear Maintainer,
thanks for this nice crate! I do have the following situation:
#[derive(Diff, PartialEq, Eq)]
pub struct ExternalType {
pub timestamp: Datetime<Utc>,
}
Are there any chances to support structs that contain external types?
Best regards,
Lewin
Attempting to apply the derive macro to
/// Identifies an ability within a card.
#[derive(Diff)]
pub struct AbilityIndex(usize);
Produces the compiler error expected parentheses: #[doc(...)]
. It also fails with the same error for comments on struct fields.
Version 0.4.0.
I want to ensure that the data is proper json when ser/de, so I made the struct_value a serde_json::Value. However, if I try to diff it I get the following JsonValue: Diff is not satisfied
#[derive(Deserialize, Debug, Clone, Serialize, PartialEq, Diff)]
pub struct Field {
pub r#type: PostgresTypes,
#[serde(default = "default_false")]
pub unique: bool,
#[serde(default = "default_false")]
pub required: bool,
#[serde(default = "default_false")]
pub primary: bool,
#[serde(default = "default_empty_json")]
pub metadata: Option<serde_json::Value>,
}
Hey! This crate is really awesome. Good work :)
I think it might be useful to implement Default
on all of the diff types โ defaulting to a "no change". There is some situations where that might be useful.
What do you think of this idea?
Cheers!
Hello!
Not that I object it, though purpose of Diff::identity() -> Self
which in fact duplicates Default::default
is a bit unclear. IMO it's irrelevant for diffable type whether it can be default or identity constructed or not.
Thanks
Would it be possible to move the serde dependency to be behind a feature flag, instead of being always required?
In diff-struct 0.3.1 (latest released version) the Debug implementation uses Removed for all three (Removed, Altered, Inserted) variants of the VecDiffType enum.
impl<T: Diff> Debug for VecDiffType<T>
where
T::Repr: Debug,
{
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
match self {
VecDiffType::Removed { index, len } => f
.debug_struct("Removed")
.field("index", index)
.field("len", len)
.finish(),
VecDiffType::Altered { index, changes } => f
.debug_struct("Removed")
.field("index", index)
.field("changes", changes)
.finish(),
VecDiffType::Inserted { index, changes } => f
.debug_struct("Removed")
.field("index", index)
.field("changes", changes)
.finish(),
}
}
}
May I want use it to store .diff()
as a log, how it possible?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.