Skip to content

Commit

Permalink
do not use return type impl trait for ZonefileFmt
Browse files Browse the repository at this point in the history
  • Loading branch information
tertsdiepraam committed Sep 27, 2024
1 parent a81e1bb commit 440cc9b
Showing 1 changed file with 24 additions and 24 deletions.
48 changes: 24 additions & 24 deletions src/base/zonefile_fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,34 @@ impl From<fmt::Error> for Error {

pub type Result = core::result::Result<(), Error>;

/// Show a value as zonefile format
pub trait ZonefileFmt {
fn show(&self, p: &mut Presenter<'_>) -> Result;
pub struct ZoneFileDisplay<'a, T: ?Sized> {
inner: &'a T,
pretty: bool,
}

fn display_zonefile(&self, pretty: bool) -> impl fmt::Display {
struct ZoneFileDisplay<'a, T: ?Sized> {
inner: &'a T,
pretty: bool,
impl<T: ZonefileFmt + ?Sized> fmt::Display for ZoneFileDisplay<'_, T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
if self.pretty {
self.inner
.show(&mut Presenter {
writer: &mut MultiLineWriter::new(f),
})
.map_err(|_| fmt::Error)
} else {
self.inner
.show(&mut Presenter {
writer: &mut SimpleWriter::new(f),
})
.map_err(|_| fmt::Error)
}
}
}

impl<T: ZonefileFmt + ?Sized> fmt::Display for ZoneFileDisplay<'_, T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
if self.pretty {
self.inner
.show(&mut Presenter {
writer: &mut MultiLineWriter::new(f),
})
.map_err(|_| fmt::Error)
} else {
self.inner
.show(&mut Presenter {
writer: &mut SimpleWriter::new(f),
})
.map_err(|_| fmt::Error)
}
}
}
/// Show a value as zonefile format
pub trait ZonefileFmt {
fn show(&self, p: &mut Presenter<'_>) -> Result;

fn display_zonefile(&self, pretty: bool) -> ZoneFileDisplay<'_, Self> {
ZoneFileDisplay {
inner: self,
pretty,
Expand Down

0 comments on commit 440cc9b

Please sign in to comment.