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

[r2r] enum from variant derive macro #1502

Merged
merged 25 commits into from
Jan 16, 2023
Merged

Conversation

borngraced
Copy link
Member

@borngraced borngraced commented Oct 14, 2022

EnumFromVariant is very useful for generating From<T> trait from one enum variant to another. Currently, this crate can only convert enum variant with only some basic inner type such as String, and Enum type just like the example below. Can not be used for tuple, struct etc for now.

// E.G, this converts from whatever Bar is to FooBar::Bar(String) and
// whatever Foor to FooBar::Foo(Foo)
#[derive(Debug, EnumFromVariant, PartialEq, Eq)]
pub enum FooBar {
    #[enum_from_variant("Bar")]
    Bar(String),
    #[enum_from_variant("Foo")]
    Foo(Foo),
}

#[derive(Debug, Display, PartialEq, Eq)]
pub enum Bar {
    Bar(String),
}

#[derive(Debug, Clone, Display, PartialEq, Eq)]
pub enum Foo {
    Foo(String),
}

#[test]
fn test_from_variant() {
    let bar = Bar::Bar("Bar".to_string());
    assert_eq!(FooBar::Bar("Bar".to_string()), bar.into());

    let foo = Foo::Foo("Foo".to_string());
    assert_eq!(FooBar::Foo(foo.clone()), foo.into());
}

…erive

# Conflicts:
#	Cargo.lock
#	mm2src/coins/Cargo.toml
#	mm2src/coins/utxo.rs
@borngraced borngraced changed the title enum from variant derive macro [r2r] enum from variant derive macro Oct 14, 2022
Copy link

@sergeyboyko0791 sergeyboyko0791 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome feature 💯
First review iteration

mm2src/derives/enum_from_variant/Cargo.toml Outdated Show resolved Hide resolved
mm2src/derives/enum_from_variant/Cargo.toml Outdated Show resolved Hide resolved
mm2src/derives/enum_from_variant/src/lib.rs Outdated Show resolved Hide resolved
mm2src/derives/enum_from_variant/src/lib.rs Outdated Show resolved Hide resolved
mm2src/derives/enum_from_variant/src/lib.rs Outdated Show resolved Hide resolved
mm2src/derives/enum_from_variant/src/lib.rs Outdated Show resolved Hide resolved
@borngraced borngraced changed the title [r2r] enum from variant derive macro [wip] enum from variant derive macro Nov 25, 2022
Signed-off-by: borngraced <samuelonoja970@gmail.com>
Signed-off-by: borngraced <samuelonoja970@gmail.com>
Signed-off-by: borngraced <samuelonoja970@gmail.com>

Signed-off-by: borngraced <samuelonoja970@gmail.com>
Signed-off-by: borngraced <samuelonoja970@gmail.com>

Signed-off-by: borngraced <samuelonoja970@gmail.com>
@borngraced borngraced changed the title [wip] enum from variant derive macro [r2r] enum from variant derive macro Dec 5, 2022
@borngraced
Copy link
Member Author

@sergeyboyko0791 @shamardy this pr is ready for another round of review

Signed-off-by: borngraced <samiodev@icloud.com>
Signed-off-by: borngraced <samiodev@icloud.com>
Signed-off-by: borngraced <samiodev@icloud.com>
Copy link

@sergeyboyko0791 sergeyboyko0791 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Next review iteration :)

mm2src/derives/enum_from/Cargo.lock Outdated Show resolved Hide resolved
mm2src/derives/enum_from/src/lib.rs Outdated Show resolved Hide resolved
mm2src/derives/enum_from/src/lib.rs Outdated Show resolved Hide resolved
mm2src/derives/enum_from/src/lib.rs Outdated Show resolved Hide resolved
mm2src/derives/enum_from/src/from_stringify.rs Outdated Show resolved Hide resolved
mm2src/derives/enum_from/src/from_stringify.rs Outdated Show resolved Hide resolved
@borngraced borngraced changed the title [r2r] enum from variant derive macro [wip] enum from variant derive macro Dec 24, 2022
Signed-off-by: borngraced <samiodev@icloud.com>
@borngraced borngraced changed the title [wip] enum from variant derive macro [r2r] enum from variant derive macro Dec 24, 2022
Signed-off-by: borngraced <samiodev@icloud.com>
Copy link

@sergeyboyko0791 sergeyboyko0791 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the fixes!
Next iteration

mm2src/derives/enum_from/src/from_stringify.rs Outdated Show resolved Hide resolved
mm2src/derives/enum_from/src/from_stringify.rs Outdated Show resolved Hide resolved
mm2src/derives/enum_from/src/from_stringify.rs Outdated Show resolved Hide resolved
mm2src/derives/enum_from/src/from_stringify.rs Outdated Show resolved Hide resolved
@borngraced borngraced changed the title [r2r] enum from variant derive macro [wip] enum from variant derive macro Dec 27, 2022
Signed-off-by: borngraced <samiodev@icloud.com>
@borngraced borngraced changed the title [wip] enum from variant derive macro [r2r] enum from variant derive macro Dec 27, 2022
Copy link

@sergeyboyko0791 sergeyboyko0791 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Last review notes 🙂

mm2src/derives/enum_from/src/from_stringify.rs Outdated Show resolved Hide resolved
mm2src/derives/enum_from/src/from_stringify.rs Outdated Show resolved Hide resolved
mm2src/derives/enum_from/src/from_stringify.rs Outdated Show resolved Hide resolved
mm2src/derives/enum_from/src/from_trait.rs Outdated Show resolved Hide resolved
mm2src/derives/enum_from/src/from_trait.rs Show resolved Hide resolved
mm2src/derives/enum_from/src/from_trait.rs Outdated Show resolved Hide resolved
mm2src/derives/enum_from/src/lib.rs Outdated Show resolved Hide resolved
mm2src/derives/enum_from/src/lib.rs Outdated Show resolved Hide resolved
mm2src/derives/enum_from/src/lib.rs Outdated Show resolved Hide resolved
Copy link

@sergeyboyko0791 sergeyboyko0791 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few suggestions only

mm2src/coins/lp_coins.rs Outdated Show resolved Hide resolved
mm2src/coins/lp_coins.rs Outdated Show resolved Hide resolved
mm2src/derives/enum_from/src/from_stringify.rs Outdated Show resolved Hide resolved
Copy link

@sergeyboyko0791 sergeyboyko0791 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One minor non-critical suggestion that may make the code more readable 🙂

mm2src/derives/enum_from/src/from_stringify.rs Outdated Show resolved Hide resolved
Signed-off-by: borngraced <samiodev@icloud.com>
Copy link

@sergeyboyko0791 sergeyboyko0791 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-approve!

Copy link
Collaborator

@shamardy shamardy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@sergeyboyko0791 sergeyboyko0791 merged commit f7cd5db into dev Jan 16, 2023
@sergeyboyko0791 sergeyboyko0791 deleted the enum_from_displaying_derive branch January 16, 2023 09:30
@borngraced borngraced mentioned this pull request Feb 17, 2023
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.

3 participants