Coder Social home page Coder Social logo

diff-struct's Introduction

Hello and welcome!

I'm a software and full-stack web developer.

Fun Facts
Favorite language Rust ๐Ÿฆ€
Favorite activities Hiking, Classical Music ๐ŸŽผ, ๐ŸŽน
Favorite composers Prokofiev, Beethoven

diff-struct's People

Contributors

agersant avatar azriel91 avatar benhall-7 avatar cinchblue avatar da-x avatar rmnscnce avatar rrichardson avatar totalkrill avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

diff-struct's Issues

Incorrect handling of optional fields with String

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.

Wrong variant names in Debug implementation for VecDiffType

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(),
        }
    }
}

Implement `Default` for Diff types

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!

Implement Diff for DateTime<Utc>

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

Q: purpose of `Diff::identity`?

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

no_std support

This would likely involve adding an alloc and std feature.

Derive macro fails for structs with comments

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.

Q: Is it possible to diff a struct where one of the fields is serde_json::Value

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>,
}

enums

I like this crate. Thank you for making it.

Are you considering adding the diffing of enums?

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?

Use Diff With generics

I am trying to use diff with generics but I am encountering issues whenever I try to add Serializing and/or debug. Specifically, that

 the trait `Serialize` is not implemented for `<T as Diff>::Repr

Here is an example,
image

How would I get around this?

Ignore PhantomData in derive

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.