1
Fork 0

Refactor away the need for some descr methods.

Instead we use `Display` impls and their `alternate` render scheme to
decide whether we want backticks or not.
This commit is contained in:
Oli Scherer 2023-10-25 16:37:21 +00:00
parent 92b41eeee6
commit c601ade3ad
5 changed files with 32 additions and 38 deletions

View file

@ -1520,21 +1520,19 @@ pub enum CoroutineKind {
impl fmt::Display for CoroutineKind {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
CoroutineKind::Async(k) => fmt::Display::fmt(k, f),
CoroutineKind::Async(k) => {
if f.alternate() {
f.write_str("`async` ")?;
} else {
f.write_str("async ")?
}
k.fmt(f)
}
CoroutineKind::Coroutine => f.write_str("coroutine"),
}
}
}
impl CoroutineKind {
pub fn descr(&self) -> &'static str {
match self {
CoroutineKind::Async(ask) => ask.descr(),
CoroutineKind::Coroutine => "coroutine",
}
}
}
/// In the case of a coroutine created as part of an async/gen construct,
/// which kind of async/gen construct caused it to be created?
///
@ -1555,21 +1553,12 @@ pub enum CoroutineSource {
impl fmt::Display for CoroutineSource {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(match self {
CoroutineSource::Block => "async block",
CoroutineSource::Closure => "async closure body",
CoroutineSource::Fn => "async fn body",
})
}
}
impl CoroutineSource {
pub fn descr(&self) -> &'static str {
match self {
CoroutineSource::Block => "`async` block",
CoroutineSource::Closure => "`async` closure body",
CoroutineSource::Fn => "`async` fn body",
CoroutineSource::Block => "block",
CoroutineSource::Closure => "closure body",
CoroutineSource::Fn => "fn body",
}
.fmt(f)
}
}