Fake-rs: Using Derive field decorators

Hello,

I am using fake-rs to generate fake data on my project's structs. It works fine if I don't add any field decorators but I would like to use formatted data rather than random strings in the fields, for example, the ship_to_state I would like it to be an actual state. There's a StateAbbr struct that implements dummy but not sure how to make it sure.

Any help in understanding on how to make this work would be appreciated.

# [...]

#[derive(Debug, Dummy)]
pub struct Order {
    order_number: String,
    created_date:String,
    requested_ship_date: String,
    cancel_after_date: String,
    ship_to_name: String,
    ship_to_store: String,
    ship_to_address: String,
    ship_to_city: String,
    #[dummy("StateAbbr")]
    ship_to_state: String,
    ship_to_zip: String,
    all_po: Vec<Po>,
}

fn main() {
    let f: Order = Faker.fake();
    dbg!(f);
}

Sorry, after playing around some more I found the solution by accident. I had to use the StateAbbr() function in the decorator. :man_facepalming:t4:

[...]
#[derive(Debug, Dummy)]
pub struct Order {
    order_number: String,
    created_date:String,
    requested_ship_date: String,
    cancel_after_date: String,
    ship_to_name: String,
    ship_to_store: String,
    ship_to_address: String,
    ship_to_city: String,
    #[dummy(faker = "StateAbbr()")]
    ship_to_state: String,
    #[dummy("ZipCode")]
    ship_to_zip: String,
    all_po: Vec<Po>,
}

'''

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.