Skip to content

Commit 8f77596

Browse files
committed
CR
1 parent 984a2e4 commit 8f77596

File tree

3 files changed

+18
-24
lines changed

3 files changed

+18
-24
lines changed

src/librustdoc/display/joined.rs renamed to src/librustdoc/display.rs

+18
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Various utilities for working with [`fmt::Display`](std::fmt::Display) implementations.
2+
13
use std::fmt::{self, Display, Formatter};
24

35
pub(crate) trait Joined: IntoIterator {
@@ -27,3 +29,19 @@ where
2729
Ok(())
2830
}
2931
}
32+
33+
pub(crate) trait MaybeDisplay {
34+
/// For a given `Option<T: Display>`, returns a `Display` implementation that will display `t` if `Some(t)`, or nothing if `None`.
35+
fn maybe_display(self) -> impl Display;
36+
}
37+
38+
impl<T: Display> MaybeDisplay for Option<T> {
39+
fn maybe_display(self) -> impl Display {
40+
fmt::from_fn(move |f| {
41+
if let Some(t) = self.as_ref() {
42+
t.fmt(f)?;
43+
}
44+
Ok(())
45+
})
46+
}
47+
}

src/librustdoc/display/maybe.rs

-17
This file was deleted.

src/librustdoc/display/mod.rs

-7
This file was deleted.

0 commit comments

Comments
 (0)