1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// 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 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 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¶m2=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;