Commit 8689e07
## Summary
Re-adds a `TryFrom<&str>` implementation for
`templated_uri::PathAndQuery` that was lost during prior refactorings,
restoring parity with `http::uri::PathAndQuery` and giving callers a
natural way to build a `PathAndQuery` from runtime string data.
`
ust
let pq = PathAndQuery::try_from("/api/v1/users?active=true")?;
`
## Behavior
- Delegates to `http::uri::PathAndQuery::try_from` and wraps the result
via the existing `From<HttpPathAndQuery> for PathAndQuery` impl.
- Errors propagate through `?` as `UriError` via the existing
`From<InvalidUri> for UriError` impl (label: `uri_invalid`). No extra
allocation, source is preserved on `Error::source()`.
- Inputs without a leading `/` are rejected. This is enforced by the
upstream `http` parser, which behaves identically across its entry
points (`try_from` returns `InvalidUri`; `from_static` panics with
*"static str is not valid path"*), so no duplicate check is added here.
## Tests
Three new unit tests in `crates/templated_uri/src/path_and_query.rs`:
- `try_from_str_succeeds` — happy path with query string.
- `try_from_str_invalid_errors` — invalid character (`/invalid path\0`)
returns `UriError` with label `uri_invalid`.
- `try_from_str_without_leading_slash_errors` — slash-less input returns
`UriError` with label `uri_invalid`.
## Not included
- No `TryFrom<&[u8]>` variant. The upstream `http` crate offers it to
let byte-oriented network code skip a UTF-8 check, but `PathAndQuery` at
this layer is composed from string templates, `&'static str`, and
`Sensitive<String>` — no concrete byte-slice caller exists. Trivial to
add later if one appears.
- No manual `CHANGELOG.md` entry — handled at release time by
`scripts/release-crate.ps1`.
---------
Co-authored-by: Kateřina Churanová <katerina.churanova@microsoft.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 3e7cc35 commit 8689e07
1 file changed
Lines changed: 67 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
137 | 137 | | |
138 | 138 | | |
139 | 139 | | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
140 | 174 | | |
141 | 175 | | |
142 | 176 | | |
| |||
220 | 254 | | |
221 | 255 | | |
222 | 256 | | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
223 | 290 | | |
0 commit comments