-
-
Notifications
You must be signed in to change notification settings - Fork 98
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
Vec of Barcodes please #166
Comments
you can do it like below, use dummy::Dummy;
use fake::{faker::barcode::raw::*, locales::EN, Fake, Faker};
#[derive(Debug, Dummy)]
pub struct Order {
#[dummy(faker = "(Isbn(EN), 4..8)")]
books: Vec<String>,
}
fn main() {
// 1d vec
// using tuple for vec (T, L), where U: Dummy<T>, usize: Dummy<L>
// U = Strig, T = Isbn(EN), L = 4..8
let isbn_vec: Vec<String> = (Isbn(EN), 4..8).fake();
println!("Vec {:?}", isbn_vec);
// 2d vec
// using tuple for vec ((T, L1), L2), where U: Dummy<T>, usize: Dummy<L1>, usize: Dummy<L2>
// U = Strig, T = Isbn(EN), L1 = 4..8, L2: 10
let isbn_vec: Vec<Vec<String>> = ((Isbn(EN), 4..8), 10).fake();
println!("Vec {:?}", isbn_vec);
let o = Faker.fake::<Order>();
println!("Order {:?}", o);
} |
Thank you @cksac; that worked great. For anyone else that googles this, here's an example of how I did it with derive (and I'm only importing fake when #[derive(Clone, Debug, Deserialize, Serialize)]
#[cfg_attr(test, derive(fake::Dummy))]
#[serde(rename_all = "camelCase")]
pub struct Request {
/// Prescription barcodes
#[serde(default, skip_serializing_if = "Vec::is_empty")]
#[cfg_attr(test, dummy(faker = "(fake::faker::barcode::en::Isbn13(), 0..4)"))]
pub prescription_barcodes: Vec<String>,
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm getting this issue:
It'd be nice if we could have a Vec of barcodes please :)
Thank you for the nice library.
The text was updated successfully, but these errors were encountered: