feat: add hurl! and local_folder! macros to make Url easier to create (#135)
Some checks failed
Compile and package harmony_composer / package_harmony_composer (push) Waiting to run
Run Check Script / check (push) Has been cancelled

* it was named `hurl!` instead of just `url!` because it was clashing with the crate `url` so we would have been forced to use it with `harmony_macros::url!` which is less sexy

Reviewed-on: #135
This commit is contained in:
2025-09-08 14:43:41 +00:00
parent b42815f79c
commit 6ea5630d30
5 changed files with 108 additions and 4 deletions

View File

@@ -51,6 +51,40 @@ impl TryFrom<String> for MacAddress {
pub type IpAddress = std::net::IpAddr;
/// Represents a URL, which can either be a remote URL or a local file path.
///
/// For convenience, the `harmony_macros` crate provides `hurl!` and `local_folder!`
/// macros to construct `Url` variants from string literals.
///
/// # Examples
///
/// ### Manual Construction
///
/// The following example demonstrates how to build `Url` variants directly. This is
/// the standard approach if you are not using the `harmony_macros` crate.
///
/// ```
/// // The `use` statement below is for the doc test. In a real project,
/// // you would use `use harmony_types::Url;`
/// # use harmony_types::net::Url;
/// let url = Url::Url(url::Url::parse("https://example.com").unwrap());
/// let local_path = Url::LocalFolder("/var/data".to_string());
///
/// assert!(matches!(url, Url::Url(_)));
/// assert!(matches!(local_path, Url::LocalFolder(_)));
/// ```
///
/// ### Usage with `harmony_macros`
///
/// If `harmony_macros` is a dependency, you can create `Url`s more concisely.
///
/// ```rust,ignore
/// use harmony_macros::{hurl, local_folder};
/// use harmony_types::Url;
///
/// let hurl = hurl!("https://example.com");
/// let local_path = local_folder!("/var/data");
/// ```
#[derive(Debug, Clone)]
pub enum Url {
LocalFolder(String),