diff --git a/README.md b/README.md index b649628..801572c 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,7 @@ Available features: - `time` - `zerocopy` - `glam` + - `url` - `always-true-rng`: expose AlwaysTrueRng - `maybe-non-empty-collections`: allow to use AlwaysTrueRng to generate non-empty collections diff --git a/fake/Cargo.toml b/fake/Cargo.toml index 7a88a1f..fabb77e 100644 --- a/fake/Cargo.toml +++ b/fake/Cargo.toml @@ -38,6 +38,7 @@ rand_core = { version = "0.6", optional = true } glam = { version = "0.28.0", optional = true } url-escape = { version = "0.1", optional = true } bson = { version = "2.10", optional = true } +url = { version = "2.5.2", optional = true } [dev-dependencies] chrono = { version = "0.4", features = ["clock"], default-features = false } diff --git a/fake/README.md b/fake/README.md index c09e2bd..57ea794 100644 --- a/fake/README.md +++ b/fake/README.md @@ -31,6 +31,7 @@ Available features: - `time` - `zerocopy` - `glam` + - `url` - `always-true-rng`: expose AlwaysTrueRng - `maybe-non-empty-collections`: allow to use AlwaysTrueRng to generate non-empty collections diff --git a/fake/src/impls/mod.rs b/fake/src/impls/mod.rs index bcf61de..c1041d0 100644 --- a/fake/src/impls/mod.rs +++ b/fake/src/impls/mod.rs @@ -27,6 +27,8 @@ pub mod std; pub mod time; #[cfg(feature = "ulid")] pub mod ulid; +#[cfg(feature = "url")] +pub mod url; #[cfg(feature = "uuid")] pub mod uuid; #[cfg(feature = "zerocopy")] diff --git a/fake/src/impls/url/mod.rs b/fake/src/impls/url/mod.rs new file mode 100644 index 0000000..7d41172 --- /dev/null +++ b/fake/src/impls/url/mod.rs @@ -0,0 +1,12 @@ +use crate::{Dummy, Fake, Faker}; +use rand::Rng; +use url::Url; + +const FQDN: &str = "https://example.com"; + +impl Dummy for Url { + fn dummy_with_rng(_: &Faker, rng: &mut R) -> Self { + let path: String = Faker.fake_with_rng(rng); + Url::parse(&format!("{FQDN}/{path}")).unwrap() + } +}