templated_uri 0.1.2

Standards-compliant URI handling with templating, safety validation, and data classification
Documentation
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

/// Derives the `UriParam` trait for newtype wrappers around URI-safe types.
///
/// This derive macro implements `UriParam` for tuple structs with exactly one field.
/// The implementation calls `as_uri_safe()` on the inner type, making it suitable for
/// use in URI templates with standard `{param}` (percent-encoded) placeholders.
///
/// # Requirements
///
/// - Must be a tuple struct (newtype pattern) with exactly one field
/// - The inner type must implement [`UriParam`]
///
/// # Example
///
/// ```
/// # use templated_uri::{UriParam, UriSafeString};
/// #[derive(UriParam)]
/// struct UserId(UriSafeString);
/// ```
///
/// This allows `UserId` to be used in URI templates where it will be properly encoded.
pub use templated_uri_macros::UriParam;
/// Derives the `UriUnsafeParam` trait for newtype wrappers with unrestricted characters.
///
/// This derive macro implements `UriUnsafeParam` for tuple structs with exactly one field.
/// The implementation delegates to the inner field's [`Display`](std::fmt::Display) impl, making it suitable for use in
/// URI templates with unrestricted `{+param}` placeholders that allow reserved characters.
///
/// # Requirements
///
/// - Must be a tuple struct (newtype pattern) with exactly one field
/// - The inner type must implement [`Display`](std::fmt::Display)
///
/// # Example
///
/// ```
/// use templated_uri::UriUnsafeParam;
///
/// #[derive(UriUnsafeParam)]
/// struct PathSegment(String);
/// ```
///
/// This allows `PathSegment` to be used in URI templates with `{+param}` syntax where
/// reserved characters like `/` should be preserved rather than percent-encoded.
pub use templated_uri_macros::UriUnsafeParam;
/// Generates URI templating and data privacy implementations for structs and enums.
///
/// This macro processes RFC 6570 URI templates and generates implementations for:
/// - `TemplatedPathAndQuery`: Methods for URI template expansion and formatting
/// - `Debug`: Custom debug representation showing the template
/// - `RedactedDisplay`: Data privacy-aware display with selective field redaction
/// - `From<T> for TargetPathAndQuery`: Conversion to target path and query
///
/// # Struct Usage
///
/// For structs, specify a URI template. Field names must match template parameter names.
///
/// ```
/// # use templated_uri::templated;
/// #[templated(template = "/topic/{topic_id}", unredacted)]
/// struct ListTopics {
///     topic_id: u32,
/// }
/// ```
///
/// ## Template Syntax
///
/// Supports RFC 6570 URI template operators:
/// - `{param}`: URI-safe encoding (percent-encoded)
/// - `{+param}`: Unrestricted (allows reserved characters like `/`)
/// - `{/param1,param2}`: Path segment expansion (`/value1/value2`)
/// - `{?param1,param2}`: Query parameter expansion (`?param1=value1&param2=value2`)
///
/// ## Data Privacy
///
/// By default, all fields use `RedactedDisplay` for privacy protection. Use attributes to control:
/// - `#[templated(template = "...", unredacted)]`: Disable redaction for all fields
/// - `#[unredacted]`: Disable redaction for a specific field
///
/// ```ignore
/// # use templated_uri::{templated, UriSafeString};
/// #[templated(template = "/{org_id}/product/{product_id}")]
/// struct ProductPath {
///     org_id: OrgId,           // Will be redacted
///     #[unredacted]
///     product_id: UriSafeString, // Will NOT be redacted
/// }
/// ```
///
/// # Enum Usage
///
/// For enums, each variant must contain exactly one field that implements `TemplatedPathAndQuery`.
/// The macro generates delegating implementations that forward to the inner type.
///
/// ```ignore
/// # use templated_uri::templated;
/// #[templated]
/// enum ApiPath {
///     User(UserPath),
///     Product(ProductPath),
/// }
/// ```
///
/// The enum will delegate all trait methods to whichever variant is active, and also generates
/// `From<VariantType>` implementations for easy construction.
pub use templated_uri_macros::templated;