feat: add hurl! and local_folder! macros to make Url easier to create (#135)
* 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:
@@ -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),
|
||||
|
||||
Reference in New Issue
Block a user