Skip to content

Commit c7147e4

Browse files
committed
Document and test UrlPartsBuilder::push_fmt
1 parent cef250d commit c7147e4

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/librustdoc/html/url_parts_builder.rs

+13
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,19 @@ impl UrlPartsBuilder {
6767
self.buf.push_str(part);
6868
}
6969

70+
/// Push a component onto the buffer, using [`format!`]'s formatting syntax.
71+
///
72+
/// # Examples
73+
///
74+
/// Basic usage (equivalent to the example for [`UrlPartsBuilder::push`]):
75+
///
76+
/// ```ignore (private-type)
77+
/// let mut builder = UrlPartsBuilder::new();
78+
/// builder.push("core");
79+
/// builder.push("str");
80+
/// builder.push_fmt(format_args!("{}.{}.html", "struct", "Bytes"));
81+
/// assert_eq!(builder.finish(), "core/str/struct.Bytes.html");
82+
/// ```
7083
crate fn push_fmt(&mut self, args: fmt::Arguments<'_>) {
7184
if !self.buf.is_empty() {
7285
self.buf.push('/');

src/librustdoc/html/url_parts_builder/tests.rs

+10
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,16 @@ fn push_front_non_empty() {
4040
t(builder, "nightly/core/str/struct.Bytes.html");
4141
}
4242

43+
#[test]
44+
fn push_fmt() {
45+
let mut builder = UrlPartsBuilder::new();
46+
builder.push_fmt(format_args!("{}", "core"));
47+
builder.push("str");
48+
builder.push_front("nightly");
49+
builder.push_fmt(format_args!("{}.{}.html", "struct", "Bytes"));
50+
t(builder, "nightly/core/str/struct.Bytes.html");
51+
}
52+
4353
#[test]
4454
fn collect() {
4555
t(["core", "str"].into_iter().collect(), "core/str");

0 commit comments

Comments
 (0)