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

Is it possible to do a 'partial' fake? #159

Closed
bbaldino opened this issue Nov 30, 2023 · 4 comments
Closed

Is it possible to do a 'partial' fake? #159

bbaldino opened this issue Nov 30, 2023 · 4 comments

Comments

@bbaldino
Copy link

bbaldino commented Nov 30, 2023

I'm wondering if there's a way to be able to set some subset of fields to specific values, and then be able to use fake-generated values for the rest of the fields? Kinda like how with default you can do something like:

let my_struct = MyStruct {
    field_one: "hello",
    ..Default::default()   
};
@cksac
Copy link
Owner

cksac commented Dec 1, 2023

you can use #[dummy(expr = "xxx")]

#[allow(dead_code)]
#[derive(Debug, Dummy)]
struct ExprStruct {
    #[dummy(faker = "1..100")]
    pub product_id: usize,
    #[dummy(expr = "\"Base\".into()")]
    pub fixed_value: String,
}

@bbaldino
Copy link
Author

bbaldino commented Dec 1, 2023

Sorry, I was referring to being able to pass a specific value in when creating an instance, not when defining the struct, is that possible?

@cksac
Copy link
Owner

cksac commented Dec 1, 2023

you can try following. e.g.

let my_struct = MyStruct {
    field_one: "hello",
    ..Faker.fake()
};

@bbaldino
Copy link
Author

bbaldino commented Dec 1, 2023

Perfect! Exactly what I needed. Thanks!

@bbaldino bbaldino closed this as completed Dec 1, 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

No branches or pull requests

2 participants