Skip to content

Commit

Permalink
CR
Browse files Browse the repository at this point in the history
  • Loading branch information
yotamofek committed Feb 10, 2025
1 parent 984a2e4 commit 8f77596
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 24 deletions.
18 changes: 18 additions & 0 deletions src/librustdoc/display/joined.rs → src/librustdoc/display.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! Various utilities for working with [`fmt::Display`](std::fmt::Display) implementations.
use std::fmt::{self, Display, Formatter};

pub(crate) trait Joined: IntoIterator {
Expand Down Expand Up @@ -27,3 +29,19 @@ where
Ok(())
}
}

pub(crate) trait MaybeDisplay {
/// For a given `Option<T: Display>`, returns a `Display` implementation that will display `t` if `Some(t)`, or nothing if `None`.
fn maybe_display(self) -> impl Display;
}

impl<T: Display> MaybeDisplay for Option<T> {
fn maybe_display(self) -> impl Display {
fmt::from_fn(move |f| {
if let Some(t) = self.as_ref() {
t.fmt(f)?;
}
Ok(())
})
}
}
17 changes: 0 additions & 17 deletions src/librustdoc/display/maybe.rs

This file was deleted.

7 changes: 0 additions & 7 deletions src/librustdoc/display/mod.rs

This file was deleted.

0 comments on commit 8f77596

Please sign in to comment.