Skip to content

Commit

Permalink
Add Uri.empty constant representing an empty URI
Browse files Browse the repository at this point in the history
  • Loading branch information
diemogebhardt committed Jul 30, 2024
1 parent 9548d28 commit 68f765f
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions src/gleam/uri.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,48 @@ pub type Uri {
)
}

/// A constant representing an empty URI, useful as a starting point for constructing
/// URIs with minimal boilerplate.
///
/// ## Examples
///
/// ```gleam
/// let empty_uri = Uri.empty
/// // -> Uri(
/// // scheme: None,
/// // userinfo: None,
/// // host: None,
/// // port: None,
/// // path: "",
/// // query: None,
/// // fragment: None,
/// // )
/// ```
///
/// ```gleam
/// // 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,
/// // )
/// ```
///
pub const empty = Uri(
scheme: None,
userinfo: None,
host: None,
port: None,
path: "",
query: None,
fragment: None,
)

/// Parses a compliant URI string into the `Uri` Type.
/// If the string is not a valid URI string then an error is returned.
///
Expand Down

0 comments on commit 68f765f

Please sign in to comment.