URL Encode A String In Rust
December 2023
There's a create that does the encoding (see below). Most of the time, what I really want is a pretty URL. This is what I'm using:
```cargo
regex = "1.10.4"
```
use Regex;
Output:
some-42-thing-for-url
This is the way to do it with actual encoding. (NOTE: I haven't tested the above to see if there are any characters that get passed that shouldn't go in the URL, but it should just be word characters in which case things should be okay.)
```cargo
urlencoding = "2.1"
```
use encode;
Output:
This%20string%20will%20be%20URL%20encoded.
Notes
-
The
.encode()call returns aCow. Calling.into_owned()is what makes it aString
TODO
☐
Test the output from the regex to make sure no invalid URL characters can make it through
end of line