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 there a way to force all Option members to be Some(foo)? #139

Closed
sztomi opened this issue Aug 12, 2023 · 2 comments
Closed

Is there a way to force all Option members to be Some(foo)? #139

sztomi opened this issue Aug 12, 2023 · 2 comments

Comments

@sztomi
Copy link

sztomi commented Aug 12, 2023

In dap-rs, fake is used to generate various structures to verify their serialization against a provided JSON schema. This works reasonably well, but the specification is full off optional fields, so Fake also ends up generating many None values in various nested structures. For verifying the serialization, it would be best if we could somehow force everything to be Some. Is there a way to accomplish that with fake? By the way, thank you very much for this excellent library, it's godsend.

@cksac
Copy link
Owner

cksac commented Aug 14, 2023

you can enable always-true-rng feature, then use it

let mut rng = AlwaysTrueRng::default();
let result: Option<i64> = Faker.fake_with_rng(&mut rng);
assert_eq!(result, Some(6442450945));

@sztomi
Copy link
Author

sztomi commented Aug 14, 2023

Thanks a lot, that's exactly what I needed!

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