From c7147e4e1acd49ea01e6d67a85c270946554783a Mon Sep 17 00:00:00 2001 From: Noah Lev Date: Mon, 10 Jan 2022 15:33:20 -0800 Subject: [PATCH] Document and test `UrlPartsBuilder::push_fmt` --- src/librustdoc/html/url_parts_builder.rs | 13 +++++++++++++ src/librustdoc/html/url_parts_builder/tests.rs | 10 ++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/librustdoc/html/url_parts_builder.rs b/src/librustdoc/html/url_parts_builder.rs index 66c879b83925c..2bb78aa7dc9c0 100644 --- a/src/librustdoc/html/url_parts_builder.rs +++ b/src/librustdoc/html/url_parts_builder.rs @@ -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('/'); diff --git a/src/librustdoc/html/url_parts_builder/tests.rs b/src/librustdoc/html/url_parts_builder/tests.rs index 43338c95010a0..636e1ab55279f 100644 --- a/src/librustdoc/html/url_parts_builder/tests.rs +++ b/src/librustdoc/html/url_parts_builder/tests.rs @@ -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");