Document and test UrlPartsBuilder::push_fmt

This commit is contained in:
Noah Lev 2022-01-10 15:33:20 -08:00
parent cef250d90b
commit c7147e4e1a
2 changed files with 23 additions and 0 deletions

View File

@ -67,6 +67,19 @@ impl UrlPartsBuilder {
self.buf.push_str(part);
}
/// Push a component onto the buffer, using [`format!`]'s formatting syntax.
///
/// # Examples
///
/// Basic usage (equivalent to the example for [`UrlPartsBuilder::push`]):
///
/// ```ignore (private-type)
/// let mut builder = UrlPartsBuilder::new();
/// builder.push("core");
/// builder.push("str");
/// builder.push_fmt(format_args!("{}.{}.html", "struct", "Bytes"));
/// assert_eq!(builder.finish(), "core/str/struct.Bytes.html");
/// ```
crate fn push_fmt(&mut self, args: fmt::Arguments<'_>) {
if !self.buf.is_empty() {
self.buf.push('/');

View File

@ -40,6 +40,16 @@ fn push_front_non_empty() {
t(builder, "nightly/core/str/struct.Bytes.html");
}
#[test]
fn push_fmt() {
let mut builder = UrlPartsBuilder::new();
builder.push_fmt(format_args!("{}", "core"));
builder.push("str");
builder.push_front("nightly");
builder.push_fmt(format_args!("{}.{}.html", "struct", "Bytes"));
t(builder, "nightly/core/str/struct.Bytes.html");
}
#[test]
fn collect() {
t(["core", "str"].into_iter().collect(), "core/str");