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

code refactoring changes with macro attributes added to mapped existing fields #12

Merged
merged 13 commits into from
Nov 16, 2024

Conversation

douggynix
Copy link
Owner

@douggynix douggynix commented Nov 16, 2024

This Pull request is the follow-up of this one with the pending required changes:
#11

The changes will add macro attributes as well for mapping struct fields:

 #[derive(DtoMapper, Debug, Default, Clone)]
#[mapper(
    dto="CustomDtoWithAttribute" ,
    no_builder=true ,
    map=[ ("email", false, ["#[serde(rename = \"email_address\")]"] ) ],
    derive=(Debug, Clone, Serialize, Deserialize),
    new_fields=[
        (
            "name: String",
            "concat_str( self.firstname.as_str(), self.lastname.as_str() )",
            ["#[serde(rename = \"full_name\")]"],
        ),
        (
          "hidden_password: String",
         r#""*".repeat( self.password.len() )"#
        ),
    ],
    macro_attr=["serde(rename_all = \"UPPERCASE\")"]
)]
    struct User {
        username: String,
        password: String,
        email: String,
        firstname: String,
        middle_name: Option<String>,
        lastname: String,
        age: u8,
    }

The macro definition above will generate this new struct with the attributes added in the mapping field.
Run this command to view the result:

cargo install cargo-expand
cargo expand --test dto_example
#[serde(rename_all = "UPPERCASE")]
pub struct CustomDtoWithAttribute {
    #[serde(rename = "email_address")]
    pub email: Option<String>,
    #[serde(rename = "full_name")]
    pub name: String,
    pub hidden_password: String,
}

@douggynix douggynix self-assigned this Nov 16, 2024
@douggynix douggynix force-pushed the feature/code-review-and-changes branch from 96d34b1 to d48e4cd Compare November 16, 2024 03:18
@douggynix
Copy link
Owner Author

@fatihaziz: Feel free to comment, I am following up with your work with macro attributes on mapping fields.

@douggynix douggynix changed the title code refactoring changes with properties added to mapped fields code refactoring changes with macro attributes added to mapped existing fields Nov 16, 2024
Adding change log to track features and history
@douggynix douggynix merged commit 55552b9 into main Nov 16, 2024
1 check passed
@douggynix douggynix deleted the feature/code-review-and-changes branch November 16, 2024 18:24
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.

1 participant