Commit 28a2988
authored
feat: Implement TryFrom<GitUrl> for url::Url (#66)
`GitUrl::url_compat_display()` is currently private, but it would be
very useful to have this functionality - in my case, normalizing an SSH
style URL is fine, especially because I do not want to bother with
handling the `'url` lifetime of `GitUrl` in my wrapper enum.
This change implements fallible conversion to `url::Url` for `GitUrl`
and `&GitUrl` via `GitUrl::url_compat_display()`.
Longer term it might be wise to re-visit the use of a lifetime for the
purpose of re-using slices of the input string - the `url::Url` crate
does not bother with such micro-optimizations either, presumably for
good reasons.
Obviously, to use a `GitUrl` as a `url::Url`, the conversion to
`url::Url` still has to happen twice (because `GitUrl::parse()` incurs
the conversion via `GitUrl::is_valid()`), but that can be optimized in a
separate change, e.g. via a new `GitUrl::parse_to_url()`, or by removing
the conversion from `GitUrl::is_valid()` altogether, leaving it to the
caller to attempt the conversion.1 parent de0e16f commit 28a2988
1 file changed
+20
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
| |||
140 | 141 | | |
141 | 142 | | |
142 | 143 | | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
143 | 162 | | |
144 | 163 | | |
145 | 164 | | |
| |||
325 | 344 | | |
326 | 345 | | |
327 | 346 | | |
328 | | - | |
| 347 | + | |
329 | 348 | | |
330 | 349 | | |
331 | 350 | | |
| |||
0 commit comments