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

feat: add url feature #190

Merged
merged 2 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions fake/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
1 change: 1 addition & 0 deletions fake/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions fake/src/impls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
12 changes: 12 additions & 0 deletions fake/src/impls/url/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use crate::{Dummy, Fake, Faker};
use rand::Rng;
use url::Url;

const FQDN: &str = "https://example.com";

impl Dummy<Faker> for Url {
fn dummy_with_rng<R: Rng + ?Sized>(_: &Faker, rng: &mut R) -> Self {
let path: String = Faker.fake_with_rng(rng);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are arbitrary string can be a valid path?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is. If path is [a-zA-Z], it must be valid.

However, I think it's better to define paths as const.
FIXED: c736536

Url::parse(&format!("{FQDN}/{path}")).unwrap()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the unwrap may panic due to path is not valid, I think we should make it alway valid path?

}
}
Loading