Skip to content

Commit f6df441

Browse files
authored
Merge pull request #735 from annmarie-switzer/update-docs
Add examples to `set_path()`
2 parents 027ec43 + 601831b commit f6df441

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

url/src/lib.rs

+13
Original file line numberDiff line numberDiff line change
@@ -1551,6 +1551,19 @@ impl Url {
15511551
/// url.set_path("data/report.csv");
15521552
/// assert_eq!(url.as_str(), "https://example.com/data/report.csv");
15531553
/// assert_eq!(url.path(), "/data/report.csv");
1554+
///
1555+
/// // `set_path` percent-encodes the given string if it's not already percent-encoded.
1556+
/// let mut url = Url::parse("https://example.com")?;
1557+
/// url.set_path("api/some comments");
1558+
/// assert_eq!(url.as_str(), "https://example.com/api/some%20comments");
1559+
/// assert_eq!(url.path(), "/api/some%20comments");
1560+
///
1561+
/// // `set_path` will not double percent-encode the string if it's already percent-encoded.
1562+
/// let mut url = Url::parse("https://example.com")?;
1563+
/// url.set_path("api/some%20comments");
1564+
/// assert_eq!(url.as_str(), "https://example.com/api/some%20comments");
1565+
/// assert_eq!(url.path(), "/api/some%20comments");
1566+
///
15541567
/// # Ok(())
15551568
/// # }
15561569
/// # run().unwrap();

0 commit comments

Comments
 (0)