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

Introduce a Uri.empty constant #798

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

diemogebhardt
Copy link

This PR is regarding issues #619 and #618. More specifically: #619 (comment).

It introduces a Uri.empty constant, useful as a starting point for constructing URIs with minimal boilerplate.

Examples

let empty_uri = Uri.empty

// -> Uri(
//   scheme: None,
//   userinfo: None,
//   host: None,
//   port: None,
//   path: "",
//   query: None,
//   fragment: None,
// )
// Create a URI by overriding only the needed fields:

let localhost_uri = Uri(..Uri.empty, scheme: Some("http"), host: Some("localhost"))

// -> Uri(
//   scheme: Some("http"),
//   userinfo: None,
//   host: Some("localhost"),
//   port: None,
//   path: "",
//   query: None,
//   fragment: None,
// )

@diemogebhardt diemogebhardt force-pushed the uri-empty branch 2 times, most recently from e29ec88 to 66ebc53 Compare February 4, 2025 07:33
@lpil
Copy link
Member

lpil commented Feb 4, 2025

Is new the right name here? What does an empty URI mean?

@diemogebhardt
Copy link
Author

diemogebhardt commented Feb 4, 2025

Is new the right name here? What does an empty URI mean?

As string, this constant represents "". What is the proper term when picturing a "" string, <a href="">, a URI/URL form field or a browser address bar without any content?

Uri.empty or Uri.blank make sense to me as a non-native speaker. The Android API has the concept of an empty URI: https://developer.android.com/reference/android/net/Uri#EMPTY

Uri.default? It's not a URI containing default values.

Uri.new? We are not really constructing anything. But as a concept it is known and might make sense. Would you prefer it to be implemented as a Uri.new() function?

@lpil
Copy link
Member

lpil commented Feb 5, 2025

Great, that's very helpful thank you. Let's add that 'equivalent to ""', like in the Android docs there, I think that is a lot clearer.

Could you remove one of the two examples please, it's quite verbose showing the same thing twice, and the HTML documentation and the link to the code already show the structure.

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

Successfully merging this pull request may close these issues.

2 participants